So far, we have been able to use GD to complete the basic needs of plotting. However, sometimes it may be hard to think of ImageString.
The five fonts that can be used are few and ugly, so we need to use the following functions. This function allows us to use the TTF font, but you
Files with these fonts are required.
<? Php
Header ("Content-type: image/png ");
$ Im = ImageCreate (400,250 );
$ Col_back = ImageColorAllocate ($ im, 136,200,152 );
$ Col_write = ImageColorAllocate ($ im, 255,255,255 );
$ Col_black = ImageColorAllocate ($ im, 0, 0 );
ImageTTFText ($ im, 160,15, 40,220, $ col_black, "C:/windows/fonts/verdana. ttf", "PNG ");
// The new content only contains this sentence. The parameters are as follows:
// $ Im needless to say.
The position 160 is the font size (pt ). The value of the 15 string is the skew angle, and the horizontal direction starts counter-clockwise.
// 40,220 is the horizontal and vertical coordinates. Note that, unlike ImageString,
// The coordinates specified in ImageString are the upper left corner of the string, while those specified in ImageTTFText are the lower left corner.
// The next $ col_black is the color,
// "C:/windows/fonts/verdana. ttf" indicates the path of the font file. In Linux, it is "/.../.....".
// It can even be "http ://....". However, I have never used it like this and it is not recommended to use it like this.
// Because things that are not on your own machine are not reliable after all, you cannot shoulder the heavy responsibilities.
// Finally, the string to be output. This is especially noteworthy,
// The string here must be encoded in UTF-8 !!!
// ASCII code 0 ~ 127 characters, ASCII code is equal to UTF-8 encoding, so we do not need to convert when outputting the Spanish string.
// If you want to output Chinese characters, a series of conversions are required.
// Sadly of www.phpx.com writes a function for converting GB2312 Code to UTF-8 code.
// My other article specifically analyzes the working principle of this function.
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