PHP pictures Add text watermark and add text Shadow _php tutorial

Source: Internet
Author: User
In PHP to add a watermark to the image we need to install the GD library for PHP, here we do not introduce the GD library installation, only to introduce how to use PHP to add text watermark image and add text shadow effect.

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.

Generated:


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.

The code is as follows Copy Code
$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:

The code is as follows Copy Code
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.

http://www.bkjia.com/PHPjc/632950.html www.bkjia.com true http://www.bkjia.com/PHPjc/632950.html techarticle in PHP to add a watermark to the image we need to install the GD library for PHP, here we do not introduce the GD library installation, only to introduce how to use PHP to add text watermark image and add text shadow effect. ...

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