Home>Article>Backend Development> What to do if php gd is garbled?

What to do if php gd is garbled?

藏色散人
藏色散人 Original
2021-11-18 10:05:31 1979browse

php gd garbled solution: 1. Convert the encoding through "iconv('gb2312','utf-8','')"; 2. Call the imagettftext() function to output the Chinese string.

What to do if php gd is garbled?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

What should I do if php gd is garbled?

Solution to the problem of GD Chinese garbled characters:

Today I carefully studied some related technologies of GD, and also studied the problem of GD Chinese garbled characters.

Using the GD library to output Chinese strings, calling imagestring is useless. You need to use the imagettftext() function. Please refer to the manual for the specific use of the imagettftext function.

Here is a usage example:

$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','面对对象')." www.phpobject.net"; imagettftext($pic,10,0,10,20,$white,$font,$str);

I gave a simple GD watermark example earlier, and only gave an example of how to use pictures to watermark Yes, here is a simple code for text watermark.

Recommended study: "PHP Video Tutorial"

The above is the detailed content of What to do if php gd is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn