imageellipse() uses the center point plus width and height. Use equal dimensions for a circle.
<?php
$image = imagecreatetruecolor(320, 220);
$background = imagecolorallocate($image, 255, 255, 255);
$green = imagecolorallocate($image, 20, 150, 90);
imagefilledrectangle($image, 0, 0, 319, 219, $background);
imageellipse($image, 160, 110, 220, 120, $green);
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>Current example first; the original tutorial examples below are retained and cleaned up for continued learning.
<?php
header ("Content-type: image/jpeg");
$width=301;$height=301;
$im = @ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
ImageColorAllocate($im,255,255,255); // background colour
$text_color=ImageColorAllocate($im,255,0,0);// ellipse line colour
imageellipse($im,150,150,290,150,$text_color); // draw ellipse
Imagejpeg ($im); // show image
imagedestroy($im); //memory is cleared.
?>
Output
imageellipse($image,$center_x,$center_y,$width,$height,$color)
$image | Image created using ImageCreate() or imagecreatetruecolor() |
$center_x | x coordinate of center ( X : Horizontal ) |
$center_y | y coordinate of center ( Y : Vertical ) |
$width | Width of the ellipse |
$height | Height of the ellipse |
$color | Color of the border by using imagecolorallocate(). |

<?php
header ("Content-type: image/jpeg");
$width=301;$height=301;
$im = @ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
ImageColorAllocate($im,255,255,255);
$text_color=ImageColorAllocate($im,255,0,0);
imageellipse($im,150,150,290,290,$text_color); // outer face
imageellipse($im,80,100,50,50,$text_color); // left eye
imageellipse($im,220,100,50,50,$text_color); // right eye
imageellipse($im,150,200,70,10,$text_color); // mouth
Imagejpeg ($im);
imagedestroy($im); //memory is cleared.
?>

<?php
header ("Content-type: image/jpeg");
$width=601;$height=601;$gap=20;
$im = @ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
ImageColorAllocate($im,255,255,255);
$text_color=ImageColorAllocate($im,0,255,255);
for($i=0;$i<=$width;$i +=$gap){
imageellipse($im,$width/2,$height/2,$width-$i,$height-$i,$text_color);
}
Imagejpeg ($im);
imagedestroy($im); //memory is cleared.
?>
Change the colours of the circle by using random numbers between 1 and 255 ( R G B )
<?php
header ("Content-type: image/jpeg");
$width=601;$height=601;$gap=20;
$im = @ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
ImageColorAllocate($im,255,255,255);
$text_color=ImageColorAllocate($im,0,255,255);
for($i=0;$i<=$width;$i +=$gap){
$r=rand(1,255);
$g=rand(1,255);
$b=rand(1,255);
$text_color = ImageColorAllocate ($im, $r, $g,$b);
imageellipse($im,$width/2,$height/2,$width-$i,$height-$i,$text_color);
}
Imagejpeg ($im);
imagedestroy($im); //memory is cleared.
?>
GD functions
imagefilledellipse()
imagearc()
imagerectangle()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.