GD Library, is the PHP processing graphics extension Library, the GD library provides a series of APIs used to process pictures, using the GD library can process pictures, or generate pictures. The GD library on the site is usually used to generate thumbnails, or to add watermarks to images, or to generate Chinese character verification codes, or to generate reports on Web site data.
To generate an effect chart:
GD Library installation of what online are, now many virtual space also support, here will not repeat. The following through my actual application of code examples and related comments to introduce you to the GD library use method.
The code is as follows |
Copy Code |
$str = "Beijing"; $STR 2 = "Air quality: mild pollution"; Generate an object from a picture $im $im = Imagecreatefromjpeg ("images/3.jpg"); Load Font Zt.ttf $FNT = "Zt.ttf"; Create a color for text fonts with white and shaded black $white =imagecolorallocate ($im, 222,229,207); $black =imagecolorallocate ($im, 50,50,50); Create a function relative to the position of the picture to facilitate calling $top = 100; $left = 60; $top 2=170; Add text to the picture, Imagettftext (Image,size,angle, X, Y,color,fontfile,text) Imagettftext ($im, 0, $left +1, $top +1, $black, $fnt, $STR); Imagettftext ($im, 0, $left, $top, $white, $fnt, $STR); Imagettftext ($im, 0, $left +1, $top 2+1, $black, $fnt, $str 2); Imagettftext ($im, 0, $left, $top 2, $white, $fnt, $str 2); The $im output Imagejpeg ($im); Destroying $im objects Imagedestroy ($im);
|
Next, explain in detail:
The code is as follows |
Copy Code |
Imagettftext (Image,size,angle, X, Y,color,fontfile,text)
|
Imagettftext () is to draw the string text to the image represented by image, starting from the coordinate x,y (0, 0), the angle is angle, color is colored, using the TrueType font file specified by Fontfile.
The coordinates represented by X,y define the basic points of the first character probably in the lower left corner of the character.
Angle at 0 degrees reads the text from left to right, and a higher value indicates a counterclockwise direction (that is, if the value is 90, the text is read from the bottom up).
Fontfile is the file name of the TrueType font you want to use.
Text is a literal string that can contain a sequence of UTF-8 characters.
The color is the index value of the colour.