* /
// Create the image
$ image = imagecreatetruecolor (300,300);
// Define the color 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 imagecolorallocate () Returns an identifier representing the color of the given rgb component. 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 0x00 to 0xff in hexadecimal. imagecolorallocate () must be called to create each color used in the image represented by image.
* /
// drawing
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 allows you to fill an elliptical arc with the specified color at the same time. With this function of this function, it is easy to draw a pie chart for statistics. Here's how to use the imagefilledarc () function
The code execution results shown in Figure 22.8:
* /
// draw lines in the picture
// Create a true color image
$ 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 the image
imagedestroy ($ img);
/ *
The code execution results shown in Figure 22.9:
* /