php gd Chinese garbled solution: 1. Open the corresponding PHP code file; 2. When outputting Chinese strings through the GD library, use the imagettftext() function to solve the garbled problem.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the Chinese garbled problem of php gd?
Today I carefully studied some related technologies of GD, and also studied the problem of Chinese garbled characters in GD.
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);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the Chinese garbled problem of php gd. For more information, please follow other related articles on the PHP Chinese website!