imagearc() draws an unfilled arc. Equal width and height create a circle; different dimensions create an elliptical arc.
<?php
$image = imagecreatetruecolor(320, 220);
$background = imagecolorallocate($image, 255, 255, 255);
$blue = imagecolorallocate($image, 30, 90, 200);
imagefilledrectangle($image, 0, 0, 319, 219, $background);
imagearc($image, 160, 110, 180, 180, 20, 300, $blue);
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=300;$height=300;
$im = @ImageCreate ($width,$height) // added one pixel for border
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 255, 0,0);
imagearc($im,150,150,290,290,0,360,$text_color); // outer face
imagearc($im,80,100,50,50,0,360,$text_color); // left eye
imagearc($im,220,100,50,50,0,360,$text_color); // right eye
imagearc($im,150,150,150,150,45,135,$text_color); // mouth
Imagejpeg ($im);
imagedestroy($im); //memory is removed.
?>
In above code we maintained $width and $height equal , $start_angle should be 0 (degree ) and $end_angle should be 360 ( degree ). imagearc($image,$center_x,$center_y,$width,$height,
$start_angle,$end_angle,$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 arc |
$height | Height of the arc |
$start_angle | Angle of the start in degree. 3 Oclock position is 0 degree. |
$end_angle | Angle of the end of the arc in degree. |
$color | Color of the borders by using imagecolorallocate(). |


<?php
header ("Content-type: image/jpeg");
$width=601;$height=601;
$im = @ImageCreate ($width,$height) // added one pixel for border
or die ("Cannot Initialize new GD image stream");
$gap=20; // change this value to increase the lines
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 0, 255,250);
imagesetthickness($im,1);
$text_color = ImageColorAllocate ($im, 255, 0,0);
for($i=0;$i<=$width;$i +=$gap){
imagearc($im,$width/2,$height/2,($width)-$i,($height)-$i,0,360,$text_color);
}
Imagejpeg ($im);
imagedestroy($im); //memory is removed.
?>
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;
$im = @ImageCreate ($width,$height) // added one pixel for border
or die ("Cannot Initialize new GD image stream");
$gap=20; // change this value to increase the lines
$background_color = ImageColorAllocate ($im, 255, 255, 255);
imagesetthickness($im,1);
$text_color = ImageColorAllocate ($im, 255, 0,0);
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);
imagearc($im,$width/2,$height/2,($width)-$i,($height)-$i,0,360,$text_color);
}
Imagejpeg ($im);
imagedestroy($im); //memory is removed.
?>
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.