Home > Article > Backend Development > PHP's GD library imagettftext function solves the problem of Chinese garbled characters, _PHP tutorial
The example in this article describes how the imagettftext function of PHP's GD library solves the problem of Chinese garbled characters. Share it with everyone for your reference. The details are as follows:
When using imagettftext to write Chinese, garbled characters often occur. The solution is to convert the Chinese string into utf-8 format. The specific code is as follows (the file format is gb2312):
$green = imagecolorallocate($im,50,100,200);
$str = iconv('gb2312','utf-8','Happiness is around you');//Solving the garbled code problem
imagettftext($im,16,0,200,100,$green,'./simhei.ttf',$str);
header("content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
?>
I hope this article will be helpful to everyone’s PHP programming design.