The Wayback Machine - https://web.archive.org/web/20230422103755/https://www.geeksforgeeks.org/php-imagearc-function/
Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | imagearc() Function

Improve Article
Save Article
Like Article
author
Mahadev99
proficient
163 published articles
Improve Article
Save Article
Like Article

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:




<?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);
  
?>

Output:
image

Program 2:




<?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);
  
?>

Output:
image

Related Articles:

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


My Personal Notes arrow_drop_up
Last Updated : 23 Aug, 2019
Like Article
Save Article
Similar Reads
Related Tutorials