(PHP 4 >= 4.0.6, PHP 5, PHP 7)

imageellipseDesenha um elipse


int imageellipse ( resource $image , int $cx , int $cy , int $w , int $h , int $color )

imageellipse() desenha um elipse centrado na posição cx, cy (em cima a esquerda é 0, 0) na imagem representada por image. W e h especifica a largura e altura do elipse, respectivamente. A cor do elipse é especificada por color.


Esta função foi adicionada no PHP 4.0.6 e requer GD 2.0.2 ou posterior que pode ser obtida em »

Exemplo #1 Exemplo imageellipse()


// cria uma imagem em branco
$image imagecreate(400300);

// prenche a cor do fundo
$bg imagecolorallocate($image000);

// escolhe uma cor para o elipse
$col_ellipse imagecolorallocate($image255255255);

// desenha o elipse

// mostra a imagem
header("Content-type: image/png");


Veja também imagefilledellipse() e imagearc().

add a note add a note

User Contributed Notes 4 notes

agentyoungsoo at hanmail dot net
239 years ago
When you wana use "ImageEllipse" function
in under GD 2.0.2 version, you can use "ImageArc" like bellow

$file_name = "test.png";

$screen_x = 300;
$screen_y = 200;

$x1 = $screen_x / 2;
$y1 = $screen_y / 2;

$radius = 30;

$image = ImageCreate($screen_x, $screen_y);
$black = ImageColorAllocate($image, 0,0,0);

ImageArc($image, $x1, $y1, $radius , $radius , 0, 360, $black);

ImagePng($image, $file_name);
237 years ago
if you want to display an ellipse in the upper left corner of an image, you can easily calculate the corresponding cx and cy values. this example will draw an ellipse having the same width and height as the image.


= 100;
$ellipse_height = 200;

$ellipse_cx = ($ellipse_width / 2);
$ellipse_cy = ($ellipse_height / 2);

$img_x = $ellipse_width;
$img_y = $ellipse_height;

$img = imagecreate($img_x, $img_y);
$bg = imagecolorallocate($img, 255,255,255);

$ellipse_color = imagecolorallocate($img, 0, 0, 0);

imageellipse($img, $ellipse_cx, $ellipse_cy, $ellipse_width, $ellipse_height, $ellipse_color);

header("Content-type: image/png");

themountainlion at gmail dot com
234 years ago
In example #1 above, the variable $bg is set but not used. Set the background to anything but black ,and it won't take effect. The example needs

imagefill($image, 0, 0, $bg);

Some other image function examples have the same issue.
simon_nuttall at hotmail dot com
236 years ago
This is an optimised and bug fixed version of nojer at yahoo dot com's rotatedellipse function. I've changed it so that the arguments are compatible with imageellipse. See notes on imagearc for original version.


function rotatedellipse($im, $cx, $cy, $width, $height, $rotateangle, $colour, $filled=false) {
// modified here from nojer's version
  // Rotates from the three o-clock position clockwise with increasing angle.
  // Arguments are compatible with imageellipse.


// This affects how coarse the ellipse is drawn.


// $px and $py are initialised to values corresponding to $angle=0.
$px=$width * $cosangle;
$py=$width * $sinangle;
  for (
$angle=$step; $angle<=(180+$step); $angle+=$step) {
$ox = $width * cos(deg2rad($angle));
$oy = $height * sin(deg2rad($angle));
$x = ($ox * $cosangle) - ($oy * $sinangle);
$y = ($ox * $sinangle) + ($oy * $cosangle);

    if (
$filled) {
triangle($im, $cx, $cy, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
triangle($im, $cx, $cy, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);
    } else {
imageline($im, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
imageline($im, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);

triangle($im, $x1,$y1, $x2,$y2, $x3,$y3, $colour) {
$coords = array($x1,$y1, $x2,$y2, $x3,$y3);
imagefilledpolygon($im, $coords, 3, $colour);

To Top