Home >Backend Development >PHP Tutorial >PHP generates 3D percentage graphic statistical effects_PHP tutorial
PHP generates 3D percentage graphic statistical effects This program is based on the data provided by the user to generate a 3D percentage image statistical effect, which is a bit like the Chinese webmaster
PHP tutorial to generate a 3D percentage graphic statistical effect
/*
This program generates 3D effect percentage picture statistics based on the data provided by the user. The effect is a bit like a Chinese webmaster
*/
$image = imagecreatetruecolor(200,200); //Create a 200*200 canvas;
//Create multiple and differentiated colors
$red = imagecolorallocate($image,255,0,0);
$blue = imagecolorallocate($image,0,0,255);
$yellow = imagecolorallocate($image,255,255,0);
$violet = imagecolorallocate($image,255,0,255);
$white = imagecolorallocate($image,255,255,255);
$black = imagecolorallocate($image,0,0,0);
//Use a for loop to create the underlying 3D effect
for($i=120;$i>100;$i--){
Imagefilledarc($image,100,$i,200,120,0,30,$red,img_arc_pie);//img_arc_pie annotation is as follows:imagefilledarc($image,100,$i,200,120,30,80,$blue,img_arc_pie);
Imagefilledarc($image,100,$i,200,120,80,360,$yellow,img_arc_pie);
}
//bool imagefilledarc (resource image, int cx, int cy, int w, int h, int s, int e, int color, int style)
//
//imagefilledarc() draws an elliptical arc using cx, cy (the upper left corner of the image is 0, 0) in the image represented by image. Returns true if successful, false if failed. w and h specify the width and height of the ellipse respectively, and the s and e parameters specify the start and end points in angles. style can be the bitwise OR (or) of the following values:
//
//img_arc_pie
//
//img_arc_chord
//
//img_arc_nofill
//
//img_arc_edged
//This layer is the effect of the top layer, so that the three-dimensional effect comes out!
Imagearc($image,100,100,200,120,0,360,$black);//Add a black border so that the 3D effect looks more obvious
Imagefilledarc($image,100,100,200,120,0,30,$red,img_arc_pie);
Imagefilledarc($image,100,100,200,120,30,80,$blue,img_arc_pie);
Imagefilledarc($image,100,100,200,120,80,360,$yellow,img_arc_pie);//Add percentage data. Of course, if necessary, you can perform certain operations in batches and input the input to the picture
$str = iconv ("gbk","utf-8","36%");//This conversion is required if you want to input Chinese. example: Occupied: 30%;
Imagettftext($image,10,360-15,100+70,115,$white,"simhei.ttf",$str);
imagejpeg($image);
imagedestroy($image);