Use the GD library to generate images with shadow text. gd shadow _ PHP Tutorial

Source: Internet
Author: User
Use the GD library to generate images with shadow text and gd shadow. The GD library is used to generate images with shadow text. the gd shadow Library is recently used to generate images for public accounts, after studying the generation of text shadow effects in the GD library, we also found that using the GD library to generate images with shadow text, gd shadow

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:

$ Str = "Beijing"; $ str2 = "air quality: Mild pollution"; // Generate an object through images $ im = imagecreatefromjpeg ("images/3.jpg "); // load the zt font. ttf $ fnt = "zt. ttf "; // create a color that is used for text font white and Shadow black $ white = imagecolorallocate ($ im, 222,229,207); $ black = imagecolorallocate ($ im, 50, 50, 50); // create a function about the relative Image position to conveniently call $ top = 100; $ left = 60; $ top2 = 170; // add text to the image, imagettftext (image, size, angle, x, y, color, fontfile, text) 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 to 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.

Please take a moment to share your article with your friends or leave a comment. Thank you for your support!

Ghost recently used the GD library to generate images for public accounts. after studying the text shadow effect of the GD library, it also found that...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.