Imagettftext function to realize image plus text watermark

Source: Internet
Author: User
Tags character set php source code
A Imagettftext function contains the following parameters, Imagettftext (Image,size,angle, x, y,color,fontfile,text) means Imagettftext () to draw the string text to Images represented by the image, starting from the coordinate x,y (0, 0) in the upper-left corner, the angle is angle, the color is colored, and the TrueType font files specified by Fontfile are used.

Depending on the GD library used by PHP, if Fontfile does not start with '/', then '. TTF ' will be added to the filename and the library will be searched for the font path.

The coordinates represented by X,y define the basic point of the first character (presumably the lower-left corner of the character). This differs from imagestring (), whose x,y defines the upper-right corner of the first character.

Angle at 0 degrees reads the text from left to right (3 o'clock), 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 (in the form: {) to access more than the first 255 characters in the font.

The color is the index value of the colour. Use a negative value with a color index to have the effect of turning off the anti-process color

For example, the following img.php source code, the application can be used for

The following are the referenced contents:
====================img.php

<?php
Header ("Content-type:image/png");
/* Notification browser, to output the image * *

$im = Imagecreate (400, 300);
/* If you do not specify an image, you can customize the size of the image * *

$im = Imagecreatefromjpeg ("gd04.jpg");

$pink = imagecolorallocate ($im, 0, 0, 0);

$fontfile = "C:\WINDOWS\Fonts\ founder static Bud TTF";
/* $fontfile The path of the font, depending on the operating system, can be Simhei.ttf (bold), Simkai. TTF (italics), Simfang. TTF (imitation), SimSun. TTC (XXFarEastFont-Arial & neo-Arial) and other GD-supported Chinese fonts * *

$str = Iconv (' GB2312 ', ' UTF-8 ', ' you want the character Watermark ');
/* Convert gb2312 Character set to UTF-8 character * *

Imagettftext ($im, 25,10,140,240, $pink, $fontfile, $STR);
/* Add Chinese Watermark * *

Imagepng ($im);
Imagedestroy ($im);
?>


If a watermark for a dynamic URL is required, the
$str = Iconv (' GB2312 ', ' UTF-8 ', ' you want the character Watermark ');
Replace with
$str = Iconv (' GB2312 ', ' UTF-8 ', $_request["id"]);
Can



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.