First make sure that the php.ini setting has not opened GD extension function, test for example
Print_r (Gd_info ());
Assuming there is a printout of the content, such as the following, 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] =)
The general process of the GD drawing is 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
Test code such as the following:
<?Phpheader ("Content-type:image/jpeg"); $width = n; Wide. High $height = n; $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 Web page Imagedestroy ($image); Fifth step: Destroy, Recycle resources?>
the test tries the pieces such as the following:
Note: GD Library is powerful enough to draw various reports (such as histogram, pie chart, etc.), thumbnails, watermark and stock charts.
Examples of thumbnail functions:
<?phpheader ("Content-type:image/png"); $width = The 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 picture