PHP | imagearc() Function

The imagearc() function is an inbuilt function in PHP which is used to create an arc of a circle centered at the given coordinates. This function returns true on success or false on failure.

Syntax:

bool imagearc( $image, $cx, $cy, $width, $height, $start, $end, 
$color )

Parameters: This function accepts eight parameters as mentioned above and described below:



  • $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
  • $cx: It is used to set x-coordinate of the center.
  • $cy: It is used to set y-coordinate of the center.
  • $width: The width of arc.
  • $height: The height of arc.
  • $start: It is used to set the arc start angle, in degrees.
  • $end: It is used to set the arc end angle, in degrees. 0° is located at the three-o’clock position, and the arc is drawn clockwise.
  • $color: It sets the color of image. A color identifier created by imagecolorallocate() function.

Return Value: This function returns true on success or false on failure.

Below programs illustrate the imagearc() function in PHP.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
  
// Set the background color of image.
$bg = imagecolorallocate($image_size, 0, 103, 0);
  
// Fill background with above selected color.
imagefill($image_size, 0, 0, $bg); 
  
// Set the colors of image
$white_color = imagecolorallocate($image_size, 255, 255, 255);
$red_color = imagecolorallocate($image_size, 255, 0, 0);
$green_color = imagecolorallocate($image_size, 0, 255, 0);
$blue_color = imagecolorallocate($image_size, 0, 0, 255);
  
// Draw the circle
imagearc($image_size, 200, 150, 200, 200, 0, 360, $white_color);
imagearc($image_size, 200, 150, 150, 150, 25, 155, $red_color);
imagearc($image_size, 260, 110, 50, 50, 0, 360, $green_color);
imagearc($image_size, 140, 110, 50, 50, 0, 360, $blue_color);
  
// Output image in the browser
header("Content-type: image/png");
imagepng($image_size);
  
// Free memory
imagedestroy($image_size);
  
?>

chevron_right


Output:
image

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
  
// Set the background color of image.
$bg = imagecolorallocate($image_size, 0, 102, 0);
  
// Fill background with above selected color.
imagefill($image_size, 0, 0, $bg); 
  
// Set the colors of image
$white_color = imagecolorallocate($image_size, 255, 255, 255);
$red_color = imagecolorallocate($image_size, 255, 0, 0);
$black_color = imagecolorallocate($image_size, 0, 0, 0);
  
// Draw the arc circle image
imagearc($image_size, 200, 150, 200, 200, 0, 360, $white_color);
imagearc($image_size, 200, 150, 150, 150, 0, 360, $red_color);
imagearc($image_size, 200, 150, 50, 50, 0, 360, $black_color);
  
// Output image in the browser
header("Content-type: image/png");
imagepng($image_size);
  
// Free memory
imagedestroy($image_size);
  
?>

chevron_right


Output:
image

Related Articles:

Reference: http://php.net/manual/en/function.imagearc.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.