Use the GD library to generate images with shadow text
This article mainly introduces how to use the GD library to generate images with shadow text. It is very detailed and recommended to you. For more information, see.
Recently, the GD library was used to generate images for public accounts. After studying the text shadow effect of the GD library, we also found that the GD library is powerful.
The GD library is an extension library for php graphics 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 is usually used to generate thumbnails, add watermarks to images, generate Chinese Character verification codes, or generate reports for website data.
The GD library is installed on the Internet and many virtual spaces are now supported. I will not describe it here. The following describes how to use the GD library through examples of actual application code and related annotations.
Source image:
Generation:
The Code is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$ Str = "Beijing "; $ Str2 = "Air Quality: mild pollution "; // Generate an object through the image $ im $ Im = imagecreatefromjpeg ("images/3.jpg "); // Load the zt. ttf font $ Fnt = "zt. ttf "; // Create a color for the white and shadow of the text font $ White = imagecolorallocate ($ im, 222,229,207 ); $ Black = imagecolorallocate ($ im, 50, 50 ); // Create a function about the relative image position for easy calling $ Top = 100; $ Left = 60; $ Top2 = 170; // Add text, imagettftext (image, size, angle, x, y, color, fontfile, text) to the image) Imagettftext ($ im, 41, 0, $ left + 1, $ top + 1, $ black, $ fnt, $ str ); Imagettftext ($ im, 41, 0, $ left, $ top, $ white, $ fnt, $ str ); Imagettftext ($ im, 43, 0, $ left + 1, $ top2 + 1, $ black, $ fnt, $ str2 ); Imagettftext ($ im, 43, 0, $ left, $ top2, $ white, $ fnt, $ str2 ); // Output $ im ImageJpeg ($ im ); // Destroy $ im object ImageDestroy ($ im ); |
Next we will explain in detail:
Imagettftext (image, size, angle, x, y, color, fontfile, text)
Imagettftext () is to draw the string text to the image, starting from x, y (0, 0 in the upper left corner), angle, color, use the TrueType font file specified by fontfile.
The coordinates represented by x and y define the basic points of the first character in the lower left corner of the character.
Angle indicates the angle. 0 degrees indicates that the text is read from left to right, and a higher value indicates that the text is read from the bottom up in a counterclockwise direction (that is, if the value is 90 ).
Fontfile is the file name of the TrueType font to be used.
Text is a text string that can contain a sequence of UTF-8 characters.
Color is the color index value.
The above is all the content of this article. I hope you will like it.