Use the GD library to create a picture with shaded text, GD Shadow _php tutorial

Source: Internet
Author: User

Use the GD library to create a picture with shaded text, GD shadow


Recently, the use of GD library for the public account of the image generation, the study of the GD library text shadow effect generated at the same time also found the strong GD library.

GD Library, is the PHP processing graphics extension Library, the GD library provides a series of APIs for processing pictures, using the GD library can process pictures, or create pictures. The GD library on the website is usually used to generate thumbnails, or to add watermarks to images, or to generate Chinese character verification codes, or to generate reports on site data.
GD Library installed what the Internet has, now a lot of virtual space is also supported, here will not repeat. The following is an example of the actual application of code and related comments for everyone to introduce the use of the GD library.

Original:

Generated:

The code is as follows:

$str = "Beijing"; $str 2 = "Air quality: mildly polluted";//Generate an object from a picture $im$im = Imagecreatefromjpeg ("images/3.jpg");//load Font zt.ttf$fnt = "Zt.ttf"; /Create color, black $white=imagecolorallocate ($im, 222,229,207) for White and shadow of text font, $black =imagecolorallocate ($im, 50,50,50);// Create a function for relative picture position, convenient to call $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); IMA Gettftext ($im, 0, $left +1, $top 2+1, $black, $fnt, $str 2); Imagettftext ($im, 0, $left, $top 2, $white, $fnt, $str 2);//Will $im output imagejpeg ($IM);//Destroy $im object Imagedestroy ($im);

Then explain in detail:

Imagettftext (Image,size,angle, X, Y,color,fontfile,text)
Imagettftext () is to draw the text of the string to the image represented by image, starting at coordinates x, y (0, 0 in the upper-left corner), with the angle of angle, and the color as colored, using the TrueType font file specified by Fontfile.

The coordinates represented by X, y define the first character's basic point, presumably at the lower-left corner of the character.

Angle is angled to 0 degrees to read 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.

Color is the index value of the colors.

The above mentioned is the whole content of this article, I hope you can like.

Please take a moment to share the article with your friends or leave a comment. We would be grateful for your support!

http://www.bkjia.com/PHPjc/974667.html www.bkjia.com true http://www.bkjia.com/PHPjc/974667.html techarticle using the GD library to generate a picture with shadowed text, GD shadow recently used the GD library for the public account of the image generation, the study of the GD library text shadow effect generated at the same time also found ...

  • 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.