Home  >  Article  >  Backend Development  >  PHP's GD library imagettftext function solves the problem of Chinese garbled characters, _PHP tutorial

PHP's GD library imagettftext function solves the problem of Chinese garbled characters, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:09988browse

PHP’s GD library imagettftext function solves the problem of Chinese garbled characters,

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):

Copy code The code is as follows:
$im = imagecreatefromjpeg('./1.jpg');
$w = imagesx($im);
$h = imagesy($im);

$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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947206.htmlTechArticlePHP’s GD library imagettftext function solves the problem of Chinese garbled characters. This article describes the example of PHP’s GD library imagettftext function solving the problem of Chinese garbled characters. problem method. Share it with everyone for your reference. Specifically...
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