First you have to determine if the php.ini setting has the GD extension function, test the following
Print_r (Gd_info ());
If there is a printout of the content as follows, then the GD feature is open:
Array ( [GD Version] = bundled (2.0.34 compatible) [FreeType support] + 1 [FreeType Linkage] = Wit H FreeType [t1lib support] + 1 [gif Read support] + 1 [gif Create support] + 1 [JPG support] = > 1 [PNG support] = 1 [WBMP support] + 1 [XPM support] = [XBM support] + 1 [JIS -mapped Japanese Font Support] =)
GD drawing general steps are as follows:
1. Create a canvas resource
2. Create a color brush
3. Drawing
4. Save picture or Output picture
5. Destroying the Memory canvas resource
The test code is as follows:
<?phpheader ("Content-type:image/jpeg"); $width = 400; width, height $height = 400; $image = Imagecreate ($width, $height); First step: Create a blank image $white = imagecolorallocate ($image, 0, 0, 0); The first call to Imagecolorallocate () fills the color palette-based image with the background color, which is the image created with Imagecreate (). $green = imagecolorallocate ($image, 0, 255, 0); Step Two: Assign color imageline to the image ($image, 0, +,-A, $green); The third step: Draw line Imagerectangle ($image, 100,40,300,100, $green); Draw Rectangle Imagearc ($image, max, 0, N, $green); Draw round imagestring ($image, +, +, "PHP is Niubi honghong!", $green); Write String $str= "abcdefghjklmnpqrstuvwxyz23456789"; $randstr = substr (Str_shuffle ($STR), 0,4); Imagestring ($image, 14, 100 , 260, $RANDSTR, $green); Captcha Imagettftext ($image, 0, $green, './msjhbd. TTF ', "Chinese vsenglish"); Chinese verification//imagejpeg ($image, './test.jpg '); Save the picture as Test.jpgimagejpeg ($image) under the current path; Fourth step: Do not add the file name, direct output to the webpage Imagedestroy ($image); Fifth step: Destroy, Recycle resources?>
The test image is as follows:
Note: GD library powerful can draw various reports (such as histogram, pie chart, etc.), thumbnails, watermark and stock charts
Thumbnail function Examples:
<?phpheader ("Content-type:image/png"); $width = Original width, high $height =; $thumb _width = (int) $width/2; $thumb _height = (int) $height/2; $dst = Imagecreate ($thumb _width, $thumb _height); Create a thumbnail drawing cloth $gray = Imagecolorallocate ($DST, +, +); $src = Imagecreatefrompng ('./me.png '); Read the original image//copy the original to the thumbnail canvas imagecopyresampled ($dst, $src, 0, 0, 0, 0, $thumb _width, $thumb _height, $width, $height); Imagepng ($DST, '/me_thumb.png '); Imagedestroy ($DST); Imagedestroy ($SRC); >
PHP uses the GD library to draw and generate a CAPTCHA image