PHP imagefilledarc() function

In this chapter you will learn:

  1. What is PHP imagefilledarc() function
  2. Syntax for PHP imagefilledarc() function
  3. Parameter for PHP imagefilledarc() function
  4. Return value for PHP imagefilledarc() function
  5. Example - Draw a pie
  6. Example - PHP imagefilledarc() function

Description

Draw a partial arc and fill it.

Syntax

PHP imagefilledarc() function has the following syntax.

bool imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style )

Parameter

PHP imagefilledarc() function has the following parameters.

  • image - An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
  • cx - x-coordinate of the center.
  • cy - y-coordinate of the center.
  • width - The arc width.
  • height - The arc height.
  • start - The arc start angle, in degrees.
  • end - The arc end angle, in degrees. 0? is located at the three-o'clock position, and the arc is drawn clockwise.
  • color - A color identifier created with imagecolorallocate().
  • style - A bitwise OR of the following possibilities:

The possible values for style:

ValueMeaning
IMG_ARC_PIEdraws a filled wedge shape with a curved edge
IMG_ARC_CHORDdraws a straight line between the starting and ending angles
IMG_ARC_NOFILLdraws the outside edge line without drawing the two lines toward the center of the arc
IMG_ARC_EDGEDdraws an unfilled wedge shape with a curved edge

Return

Returns TRUE on success or FALSE on failure.

Example 1


<?php/*from   j  a v  a2 s  .c o  m*/

// create image
$image = imagecreatetruecolor(100, 100);

// allocate some colors
$gray     = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$navy     = imagecolorallocate($image, 0x00, 0x00, 0x80);
$red      = imagecolorallocate($image, 0xFF, 0x00, 0x00);

imagefilledarc($image, 50, 50, 100, 50, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 45, 75 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 75, 360 , $red, IMG_ARC_PIE);


// flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

Example 2

You can combine these four style together.

IMG_ARC_CHORD and IMG_ARC_PIE cannot be combined together.


imagefilledarc($image, 200, 150, 200, 200, 345, 15, $green,IMG_ARC_CHORD | IMG_ARC_NOFILL);
imagefilledarc($image, 200, 150, 200, 200, 345, 15, $green,IMG_ARC_EDGED | IMG_ARC_NOFILL); 
Example:

<?php /* j  a  v  a2 s. c o m*/
  $myImage = imagecreate( 500, 500 ); 
  $myGray = imagecolorallocate( $myImage, 204, 204, 204 ); 
  $myBlack = imagecolorallocate( $myImage, 0, 0, 0 ); 
  imagefilledarc($image, 200, 150, 200, 200, 345, 15, $green,IMG_ARC_CHORD | IMG_ARC_NOFILL);
  header( "Content-type: image/png" ); 
  imagepng( $myImage ); 
  imagedestroy( $myImage ); 
?> 

Next chapter...

What you will learn in the next chapter:

  1. What is PHP imageline() function
  2. Syntax for PHP imageline() function
  3. Parameter for PHP imageline() function
  4. Return value for PHP imageline() function
  5. Example -
  6. Note for imagecreate() error
Home » PHP Tutorial » PHP Image Functions
PHP imagearc() function
PHP imagecreate() function
PHP imagecreatetruecolor () function
PHP imageellipse() function
PHP imagefilledarc() function
PHP imageline() function
PHP imagepolygon() function
PHP imagerectangle() function
PHP imagesetpixel() function
PHP imagettftext() function