Using the GD library to generate pictures with shaded text _php tips

Source: Internet
Author: User

The recent use of the GD library for micro-letter public accounts of the picture generation, studied the GD library text shadow effect of the generation also found the GD library strong.

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

Original:

To generate an effect chart:

The code is as follows:

$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";
Creates a color that is used for text fonts in 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 the invocation of the
$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);
Destruction of $im Objects
Imagedestroy ($im);

Next, explain in detail:

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.

The above mentioned is the entire content of this article, I hope you can enjoy.

Please take a moment to share the article with your friends or leave a comment. We will sincerely thank you for your support!

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.