Solve the problem of GD Chinese garbled characters

Source: Internet
Author: User
To solve the problem of GD Chinese garbled text, I carefully studied some related GD technologies today, and also studied the problem of GD Chinese garbled text.

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'). " ";
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.

$ Pic=Imagecreate(250,30);
$ Black=Imagecolorallocate($ Pic,0,0,0);
$ White=Imagecolorallocate($ Pic,255,255,255);
$ Font="C: // WINDOWS // Fonts // simhei. ttf";
$ Str='Php'.Iconv('Gb2312','Utf-8','Face object')."";
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: 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.