这篇文章主要讲解了“怎么解决php gd乱码问题”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么解决php gd乱码问题”吧!
php gd乱码的解决办法:1、通过“iconv('gb2312','utf-8','')”转换编码;2、调用imagettftext()函数输出中文字符串即可。

本文操作环境:windows7系统、PHP7.1版、DELL G3电脑
php gd 乱码怎么办?
解决GD中文乱码问题:
今天仔细研究了下GD的一些相关技术,顺手也研究下GD中文乱码的问题。
使用GD库输出中文字符串,调用imagestring是没有用的。需要使用imagettftext()函数。imagettftext函数的具体使用就参考手册啦。
下面给个使用实例:
$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);前面我给出一个简单的GD水印实例,只举例说明了使用图片如何水印的,这里给出一个文字水印的简单代码。
<?php
$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);
header("Content-type: image/jpeg");
$filename='../src/images/photo.jpg';
$im=imagecreatefromjpeg($filename);
imagecopymerge($im,$pic,0,0,0,0,250,30,50);
imagejpeg($im);
?>感谢各位的阅读,以上就是“怎么解决php gd乱码问题”的内容了,经过本文的学习后,相信大家对怎么解决php gd乱码问题这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是天达云,小编将为大家推送更多相关知识点的文章,欢迎关注!