This article describes how to use PHP to plot 3D slice statistical charts and image scaling instances. This article provides sample code that includes instructions and comments, for more information, see section 1. use the function of the php gd library to create a 3D sector statistical chart.
<? Php header ("content-type", "text/html; charset = utf-8");/* slice chart */$ image = imagecreatetruecolor (100,100 ); /* Create a canvas * // * set the color required for the canvas */$ 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);/* fill in the background color */imagefill ($ image, 0, 0, $ white);/* 3D preparation */for ($ I = 60; $ I> 50; $ I --) {imagefilledarc ($ image, 50, $ I, 100, 50,-160, 40, $ darknavy, IMG_ARC_PIE); imagefilledarc ($ image, 50, $ I, 100, 50, 40, 75, $ darkgray, IMG_ARC_PIE); imagefilledarc ($ image, 50, $ I, 100, 50, 75,200, $ darkred, IMG_ARC_PIE);}/* draw an elliptical arc and fill in */imagefilledarc ($ image, 50, 50,100, 50,-160, 40, $ darknavy, IMG_ARC_PIE ); imagefilledarc ($ image, 50, 50,100, 50, 40, 75, $ darkgray, IMG_ARC_PIE); imagefilledarc ($ image, 50, 50,100, 50, 75,200, $ darkred, IMG_ARC_PIE ); /* draw a string */imagestring ($ image, 3, 15, 55, "30%", $ white); imagestring ($ image, 3, 45, 35, "60% ", $ white); imagestring ($ image, 3, 60, 60, "10%", $ white ); /* Output image */header ("content-type: image/png"); imagepng ($ image);/* release resources */imagedestroy ($ image);?>
Effect:
2. scale the image
SOURCE Image size
<? Php headers ("content-type", "text/html; charset = utf-8 "); /** image scaling * @ param string $ filename image url * @ param int $ width sets the maximum width of image scaling * @ param int $ height sets the maximum height of image scaling */ function thumb ($ filename, $ width = 130, $ height = 130) {/* obtain the size of the source image */list ($ width_orig, $ height_orig) = getimagesize ($ filename ); /* calculate the height and width of the proportional ratio based on the parameter $ width and $ height */if ($ width & ($ width_orig <$ height_orig )) {$ width = ($ height/$ height_orig) * $ w Idth_orig;} else {$ height = ($ width/$ width_orig) * $ height_orig;}/* Create a canvas with a new size */$ image_p = imagecreatetruecolor ($ width, $ height);/* get image resources */$ image = imagecreatefrompng ($ filename);/* scale by imagecopyresampled */imagecopyresampled ($ image_p, $ image, 0, 0, 0, 0, $ width, $ height, $ width_orig, $ height_orig);/* save the scaled image and name */imagepng(%image_p,'test.png '); /* release resources */imagedestroy ($ image_p); imagedestroy ( $ Image);}/* call the function */thumb('1.png ');?>Scaled size
Effect: