Open In App

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:

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:

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:

Related Articles:

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


Article Tags :