Add text to a picture (support Chinese)//php function

Source: Internet
Author: User
<?php
// **************************************** //
Function: Add text to a picture
Parameters: $img picture file name
$new _img Save the picture file name, if blank indicates no save picture
$text String Contents
Text_size string Size
Text_angle Font string Output angle
text_x string Output x coordinates
text_y string output y-coordinate
$text _font Font file name
$r, $g, $b string color RGB value
// **************************************** //
function Img_text ($img, $new _img, $text, $text _size, $text _angle, $text _x, $text _y, $text _font, $r, $g, $b) {

$text =iconv ("gb2312", "UTF-8", $text);
Header ("Content-type:image/gif");
$im = @imagecreatefromstring (file_get_contents ($img)) or Die ("Open picture Failed!");
$color = Imagecolorallocate ($im, $r, $g, $b);

Imagettftext (int im, int size, int angle, int x, int y, int col, string fontfile, string text):
This function writes TTF (TrueType Fonts) font text to a picture.
Parameter: size is the dimension of zigzag;
Angle for the angle of the font, clockwise calculation, 0 degrees to the level (from left to right), 90 degrees to the top of the text;
X,y two parameter is the coordinate value of the text (the origin point is upper left corner);
Col is the color of the word;
Fontfile is the name of the font file;
Text is the string content.
Imagettftext ($im, $text _size, $text _angle, $text _x, $text _y, $color, $text _font, $text);

if ($new _img== ""):
Imagegif ($im); Do not save pictures, show only
Else
Imagegif ($im, $new _img); Save picture, but not show
endif

Imagedestroy ($im); End graphics, freeing up memory space
}

?>

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.