Create a picture with shaded text using the GD library _php tutorial

Source: Internet
Author: User

Create a picture with shaded text using the GD library


This article mainly introduces the use of the GD library to generate a picture with shadow text, very meticulous, recommended to everyone, the need for friends can refer to the next

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

$str = "Beijing";

$STR 2 = "Air quality: mild pollution";

Create an object from a picture $im

$im = Imagecreatefromjpeg ("images/3.jpg");

Loading Font Zt.ttf

$FNT = "Zt.ttf";

Create colors for the white and Shadow Black of the text font

$white =imagecolorallocate ($im, 222,229,207);

$black =imagecolorallocate ($im, 50,50,50);

Create a function for relative picture position, easy to call

$top = 100;

$left = 60;

$top 2=170;

Add text to a 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);

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.

http://www.bkjia.com/PHPjc/975123.html www.bkjia.com true http://www.bkjia.com/PHPjc/975123.html techarticle using the GD library to generate a picture with shaded text This article mainly introduces the use of the GD library to generate a picture with shadow text, very meticulous, recommended to everyone, the need for friends can refer to ...

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