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

What to do if php gd is garbled?

藏色散人
Release: 2023-03-13 21:40:01
Original
2095 people have browsed it

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

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.

<?php 
$pic=imagecreate(250,30); 
$black=imagecolorallocate($pic,0,0,0); 
$white=imagecolorallocate($pic,255,255,255); 
$font="C://WINDOWS//Fonts//simhei.ttf";  
$str =&#39;php&#39;.iconv(&#39;gb2312&#39;,&#39;utf-8&#39;,&#39;面对对象&#39;)." www.phpobject.net"; 
imagettftext($pic,10,0,10,20,$white,$font,$str);
header("Content-type: image/jpeg");
$filename=&#39;../src/images/photo.jpg&#39;;
$im=imagecreatefromjpeg($filename);
imagecopymerge($im,$pic,0,0,0,0,250,30,50);
imagejpeg($im);
?>
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template