Home  >  Article  >  Backend Development  >  关于imagettftext乱码的问题

关于imagettftext乱码的问题

WBOY
WBOYOriginal
2016-06-06 20:18:011439browse

imagettftext函数在windows下中文显示正常,在linux下中文就出现了乱码。。。
核心代码如下:

<code>//此处省略N行。。。
$image = imagecreatetruecolor($width, $height);
$color = imagecolorallocate($image, $red, $green, $blue);
imagefill($image, 0, 0, $color);
$tcolor = imagecolorallocate($image, $tred, $tgreen, $tblue);
//imagestring ($image,  $fontfile,  20 ,  20 ,  "Hello world!" ,  $tcolor);
//echo floor(($height - $fontinfo['height']) / 2);die;
imagettftext($image, $tsize, 0, ($width - $fontinfo['width']) / 2, $height / 2, $tcolor, $fontfile, $text);
//此处省略N行。。。</code>

转码什么的都试过了,不行!也觉得不是编码的问题。。。
linux下也已经安装了msyh.ttf字体。。。

windows下显示:

关于imagettftext乱码的问题

linux下显示:

关于imagettftext乱码的问题

还望各位兄弟姐妹看看,小弟先谢过了!

回复内容:

imagettftext函数在windows下中文显示正常,在linux下中文就出现了乱码。。。
核心代码如下:

<code>//此处省略N行。。。
$image = imagecreatetruecolor($width, $height);
$color = imagecolorallocate($image, $red, $green, $blue);
imagefill($image, 0, 0, $color);
$tcolor = imagecolorallocate($image, $tred, $tgreen, $tblue);
//imagestring ($image,  $fontfile,  20 ,  20 ,  "Hello world!" ,  $tcolor);
//echo floor(($height - $fontinfo['height']) / 2);die;
imagettftext($image, $tsize, 0, ($width - $fontinfo['width']) / 2, $height / 2, $tcolor, $fontfile, $text);
//此处省略N行。。。</code>

转码什么的都试过了,不行!也觉得不是编码的问题。。。
linux下也已经安装了msyh.ttf字体。。。

windows下显示:

关于imagettftext乱码的问题

linux下显示:

关于imagettftext乱码的问题

还望各位兄弟姐妹看看,小弟先谢过了!

%e6%88%91urlencode('我')的结果,是不是通过URL进行参数传递没有解码的问题。
我很奇怪windows上是白色的,怎么Linux下就黄了。。

图片水印出现乱码,一般是两个问题。

  • 文本编码是否统一为utf8

  • GD库是否启用JIS-mapped Japanese Font Support

编码不统一,那就统一一下,启用JIS-mapped Japanese Font Support了,就关闭即可。

什么?你说JIS-mapped Japanese Font Support怎么关闭?

我的方法是重新编译php-gd拓展。

确认过了
文件编码是一致的;
编译参数没有加 --enable-gd-jis-conv的;
windows下测试正常就直接上传到linux服务器了。。。

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