The GD Library is an extension library for php image processing. the GD Library provides a series of APIs for image processing. you can use the GD library to process images or generate images, the GD Library on websites is usually used to generate thumbnails or add watermarks to images. for the latest PHP version, generating thumbnails or adding watermarks is basically not processed by a dedicated GD Library. php can directly process simple image applications, such as the processing diagram mentioned.
The GD Library is an extension library for php image processing. the GD Library provides a series of APIs for image processing. you can use the GD library to process images or generate images, the GD Library on websites is usually used to generate thumbnails or add watermarks to images. for the latest PHP version, generating thumbnails or adding watermarks is basically not processed by a dedicated GD Library. php can directly process simple image applications, such as processing image thumbnails and adding watermarks to images, image verification code, etc. Currently, the most widely used php gd diagram should be a pie chart or a statistical chart. Below is an interface source code generated by a php GD Library pie chart and runs it directly, A blue-dominated pie chart can be generated.
Program running preview:
PHP code
-
- // Picture width and height
- $ W = isset ($ _ GET ['w'])? Intval ($ _ GET ['w']): 400;
- $ H = isset ($ _ GET ['H'])? Intval ($ _ GET ['H']): 200;
- $ Title = $ _ GET ['t'];
- // Color Library
- $ Color_arr = array (
- Array (0, 0, 255 ),
- Array (255 ),
- Array (255 ),
- Array (255 ),
- Arrays (120,120,255 ),
- Arrays (150,150,255 ),
- Arrays (180,180,255 ),
- Arrays (210,210,255 ),
- Array (0,255, 0 ),
- Arrays (120,255,120 ),
- Arrays (150,255,150 ),
- Arrays (180,255,180 ),
- Arrays (210,255,210 ),
- Array (255, 0, 0 ),
- Array (255, 30, 30 ),
- Array (255, 60, 60 ),
- Array (255, 90, 90 ),
- Arrays (255,120,120 ),
- Arrays (255,150,150 ),
- Arrays (255,180,180 ),
- Arrays (255,210,210 ),
- Array (255,255, 0 ),
- Array (255, 0, 255 ),
- Array (255, 60, 255 ),
- Array (255, 90, 255 ),
- Arrays (255,120,255 ),
- Arrays (255,150,255 ),
- Arrays (255,180,255 ),
- Arrays (255,210,255 ),
- Arrays (0,255,255 ),
- Arrays (90,255,255 ),
- Arrays (120,255,255 ),
- Arrays (150,255,255 ),
- Arrays (180,255,255 ),
- Arrays (210,255,255 ),
- Array (50, 50, 50 ),
- Array (70, 70 ),
- Array (90, 90, 90 ),
- Arrays (110,110,110 ),
- Arrays (130,130,130 ),
- Arrays (150,150,150 ),
- Arrays (170,170,170 ),
- Arrays (190,190,190 ),
- );
- // Value
- $ Points = isset ($ _ GET ['Ps'])? Explode (',', $ _ GET ['Ps']): array (, 1 );
- // Value corresponding name
- $ Pts = isset ($ _ GET ['PTS '])? Explode (',', $ _ GET ['PTS ']): array ('1', '2', '3 ');
- $ Cnt = count ($ points );
- // Total value
- $ Total = 0;
- $ Tlen = 0;
- For ($ I = 0; $ I <$ cnt; $ I ++ ){
- $ Total + = $ points [$ I];
- $ Tlen = $ tlen> strlen ($ pts [$ I])? $ Tlen: strlen ($ pts [$ I]);
- }
- // Shortest side
- $ Min_wh = ($ W-2 * ($ tlen + 8) * ImageFontWidth (2)> ($ H-10 )? $ H: ($ W-2 * ($ tlen + 8) * ImageFontWidth (2 ));
- // Create an image
- $ Im = imagecreate ($ w, $ h );
- // The background color of the image is white.
- $ White = imagecolorallocate ($ im, 255,255,255 );
- $ Black = imagecolorallocate ($ im, 0, 0, 0 );
- ImageFill ($ im, 0, 0, $ white );
- // Center coordinate
- $ Cx = $ w/2;
- $ Cy = $ h/2 + 20;
- // Width and height of the circle's external rectangle
- $ Cw = $ min_wh-65;
- $ Ch = $ min_wh-65;
- $ Start = 0;
- $ End = 0;
- For ($ I = 0; $ I <$ cnt; $ I ++ ){
- // Slice color
- $ Color = $ I> = 43? Imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255): imagecolorallocate ($ im, $ color_arr [$ I] [0], $ color_arr [$ I] [1], $ color_arr [$ I] [2]);
- $ Color = imagecolorallocate ($ im, $ color_arr [$ I] [0], $ color_arr [$ I] [1], $ color_arr [$ I] [2]);
- // Start and end angles
- $ Start = $ end;
- $ End = $ start + $ points [$ I]/$ total * 360;
- Imagefilledarc ($ im, $ cx, $ cy, $ cw, $ ch, $ start, $ end, $ color, IMG_ARC_PIE );
- $ Notel1x = $ cx + cos (deg 2rad ($ start/2 + $ end/2) * $ cw/2;
- $ Notel1y = $ cy + sin (deg 2rad ($ start/2 + $ end/2) * $ cw/2;
- $ Notel2x = $ cx + cos (deg 2rad ($ start/2 + $ end/2) * ($ cw/2 + 10 );
- $ Notel2y = $ cy + sin (deg 2rad ($ start/2 + $ end/2) * ($ cw/2 + 10 );
- Imageline ($ im, $ notel1x, $ notel1y, $ notel2x, $ notel2y, $ black );
- $ Str = strlen ($ pts [$ I])? $ Pts [$ I]. "(". (substr ($ points [$ I]/$ total * 100,0, 5 )). "%)": ($ I + 1 ). "(". (substr ($ points [$ I]/$ total * 100,0, 5 )). "% )";
- If ($ notel2x> $ notel1x ){
- $ Notel3x = $ notel2x + 10;
- $ Notestrx = $ notel2x + 10;
- } Else {
- $ Notel3x = $ notel2x-10;
- $ Notestrx = $ notel2x-10-ImageFontWidth (2) * strlen ($ str );
- }
- $ Notel3y = $ notel2y;
- $ Notestry = $ notel2y-10;
- Imageline ($ im, $ notel2x, $ notel2y, $ notel3x, $ notel3y, $ black );
- Imagestring ($ im, 2, $ notestrx, $ notestry, $ str, $ black );
- }
- $ Wf5 = ImageFontWidth (5 );
- $ T_len = $ wf5 * strlen ($ title );
- // Echo $ cw. ''. $ ch; die ();
- Imagestring ($ im, 5, $ w/2-$ t_len/2, 5, $ title, $ black );
- // Flush image
- Header ('content-type: image/gif ');
- Imagegif ($ im );
- Imagedestroy ($ im );
- ?>