Home  >  Article  >  Backend Development  >  How to solve the Chinese garbled problem of php gd

How to solve the Chinese garbled problem of php gd

藏色散人
藏色散人Original
2022-01-20 11:04:282476browse

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.

How to solve the Chinese garbled problem of php gd

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!

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