*/
// Create an image
$ Image = imagecreatetruecolor (300,300 );
// Define the color required to draw a 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 color to an image description int imagecolorallocate (resource image, int red, int green, int blue) imagecolorallocate () returns an identifier, represents a color composed of a given rgb component. The image parameter is the return value of the imagecreate () function. Red, green, and blue are the required colors respectively. These parameters are integers from 0 to 255 or hexadecimal values 0x00 to 0xff. Imagecolorallocate () must be called to create the color of each image used in the image.
*/
// Draw
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 fills an elliptical arc with a specified color. With this function, you can easily draw a pie chart for statistics. The following describes how to use the imagefilledarc () function.
The execution result of the code is shown in figure 22.8:
*/
// Draw lines in the image
// Create a true color image
$ Img = imagecreatetruecolor (0, 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 the image
Imagedestroy ($ img );
/*
The execution result of the code is shown in figure 22.9:
*/