*/
//Create image
$image=imagecreatetruecolor(300,300);
//Define the colors needed to draw the pie chart
$white=imagecolorallocate($image, 0xff, 0xff, 0xff);
$gray=imagecolorallocate($image, 0xc0, 0xc0, 0xc0);
$darkgray=imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy=imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy=imagecolorallocate($image, 0x00, 0x00, 0x50);
$red=imagecolorallocate($image, 0xff, 0x00, 0x00);
$darkred=imagecolorallocate($image, 0x90, 0x00, 0x00);
/*
imagecolorallocate -- Assign a color to an image. Description: int imagecolorallocate (resource image, int red, int green, int blue). imagecolorallocate() returns an identifier that represents the color composed of the given rgb components. The image parameter is the return value of the imagecreate() function. red, green and blue are the red, green and blue components of the desired color respectively. These parameters are integers from 0 to 255 or hexadecimal 0x00 to 0xff. imagecolorallocate() must be called to create each color used in the image represented by image.
*/
//Draw a picture
for($i=160;$i > 150; $i--)
{
imagefilledarc($image, 150, $i, 200, 80, 0, 45, $darknavy, img_arc_pie);
imagefilledarc($image, 150, $i, 200, 80, 45, 75, $darkgray, img_arc_pie);
imagefilledarc($image, 150, $i, 200, 80, 75, 360, $darkred, img_arc_pie);
}
imagefilledarc($image, 150, 150, 200, 80, 0, 45, $navy, img_arc_pie);
imagefilledarc($image, 150, 150, 200, 80, 45, 75, $gray, img_arc_pie);
imagefilledarc($image, 150, 150, 200, 80, 75, 360, $red, img_arc_pie);
header('content-type: image/png');
imagepng($image);
imagedestroy($image);
/*
The imagefilledarc() function can draw an elliptical arc and fill it with a specified color at the same time. Using this function, you can easily draw a pie chart for statistics. The following demonstrates how to use the imagefilledarc() function
The execution result of this code is shown in Figure 22.8:
*/
//Draw lines on the picture
//Create true color images
$img=imagecreatetruecolor(300,300);
$white=imagecolorallocate($img,255,255,255);
$red=imagecolorallocate($img,255,0,0);
$green=imagecolorallocate($img,0,255,0);
//Draw an ellipse on the image
imagefilledellips tutorial e($img,150,150,250,100,$red);
imagefilledellipse($img,150,150,100,250,$green);
//Output image
header("content-type: image/png");
imagepng($img);
//Destroy image
imagedestroy($img);
/*
The execution result of this code is shown in Figure 22.9:
*/