Solve the Problem of GD Chinese garbled characters

Source: Internet
Author: User

Today, I have carefully studied some related GD technologies and studied the Chinese Garbled text of GD.

Using the GD library to output a Chinese string, it is useless to call imagestring. You need to use the imagettftext () function. For details about how to use the imagettftext function, refer to the manual.

Here is an example:


$ Pic = imagecreate (250,30 );
$ Black = imagecolorallocate ($ pic, 0, 0 );
$ White = imagecolorallocate ($ pic, 255,255,255 );
$ Font = "C: // WINDOWS // Fonts // simhei. ttf"; // The path here must be the character path.
$ Str = 'php'. iconv ('gb2312', 'utf-8', 'Face object'). "www.phpobject.net ";
Imagettftext ($ pic, 10, 0, 10, 20, $ white, $ font, $ str );

In the previous section, I provided a simple GD watermark example to illustrate how to use an image watermark. Here is a simple code for text watermark.


<? Php
$ Pic = imagecreate (250,30 );
$ Black = imagecolorallocate ($ pic, 0, 0 );
$ White = imagecolorallocate ($ pic, 255,255,255 );
$ Font = "C: // WINDOWS // Fonts // simhei. ttf ";
$ Str = 'php'. iconv ('gb2312', 'utf-8', 'Face object'). "www.phpobject.net ";
Imagettftext ($ pic, 10, 0, 10, 20, $ white, $ font, $ str );

header("Content-type: image/jpeg");
$filename='../src/images/photo.jpg';
$im=imagecreatefromjpeg($filename);
imagecopymerge($im,$pic,0,0,0,0,250,30,50);
imagejpeg($im);
?>

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.