Computer >> Computer tutorials >  >> Programming >> PHP

imagearc() function in PHP


The imagearc() function is used to draw an arc.

Syntax

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

Parameters

  • $img: Creates an image with imagecreatetruecolor().

  • $cx: x-coordinate of the center.

  • $cy: y-coordinate of the center.

  • $width: The width of arc.

  • $height: The height of arc.

  • $start: The arc start angle, in degrees.

  • $end: The arc end angle in degrees.

  • $color: It sets the color of image.

Return

The imagearc() function returns the TRUE on success or FALSE on failure.

Example

The following is an example:

<?php
   $img = imagecreatetruecolor(200, 200);
   $one = imagecolorallocate($img, 100, 50, 255);
   $two = imagecolorallocate($img, 30, 255, 150);  
   imagearc($img, 100, 100, 200, 200, 0, 360, $one);
   imagearc($img, 130, 50, 100, 150, 25, 155, $two);
   header("Content-type: image/png");
   imagepng($img);
   imagedestroy($img);
?>

Output

The following is the output:

imagearc() function in PHP

Example

Let us see another example wherein we have different coordinates and angle for arc:

<?php
$img = imagecreatetruecolor(250, 250);
$one = imagecolorallocate($img, 100, 90, 255);
$two = imagecolorallocate($img, 100, 255, 190);  
imagearc($img, 130, 100, 200, 200, 0, 360, $one);
imagearc($img, 140, 50, 140, 150, 95, 155, $two);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>

Output

The following is the output:

imagearc() function in PHP