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

How to solve the Chinese garbled problem of php gd

藏色散人
Release: 2023-03-14 21:46:01
Original
2669 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template