+

PHP Imagearc () Function

Syntax:
bool imagearc ($image, $cx, $cy, $width, $height, $start, $end, $color) 
Parameters:This function takes eight parameters as above and described below:
  • $image:returned by one of the create functions images such as imagecreatetruecolor(). Used to create the size of the image.
  • $cx:is used to set the x-coordinate of the center.
  • $cy:is used to setting the y-coordinate of the center.
  • $width:the width of the arc.
  • $height:the height of the arc.
  • $start:is used to set the angle of the start of the arc in degrees.
  • $end:is used to set the angle of the end of the arc in degrees. 0 ° is at the three o`clock position and the arc is drawn clockwise.
  • $color:sets the color of the image. Color identifier generated by the imagecolorallocate() function.
Return value:This function returns true on success or false on error.The programs below illustrate the imagearc() functionin PHP.Program 1:  
// Create image or blank image size . $image_size = imagecreatetruecolor (500, 300);  
// Set the background color of the image. $bg = imagecolorallocate ( $image_size , 0, 103, 0);  
// Fill the background with the selected color above. imagefill ( $image_size , 0, 0, $bg );  
// Set the image colors $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 a 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 to browser header ( "Content-type: image / png" ); imagepng ( $image_size );  
// Free memory imagedestroy ( $image_size );  
?>
Output: Program 2:  
// Create the size of the image or blank image. $image_size = imagecreatetruecolor (500, 300);  
// Set the background color of the image. $bg = imagecolorallocate ( $image_size , 0, 102, 0);  
// Fill the background with the selected color above. imagefill ( $image_size , 0, 0, $bg );  
// Set the image colors $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 an image of a circular arc 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 to browser header ( "Content-type: image / png" ); imagepng ( $image_size );  
// Free memory imagedestroy ( $image_size );  
?>
Output: Related Articles:
  • PHP | Imagepolygon() Function
  • PHP | Imagefilledellipse() Function
  • PHP | Imagefilledpolygon() function
Link: http://php.net/manual/en/function.imagearc.php
Get Solution for free from DataCamp guru