欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

关于imagettftext乱码的问题

程序员文章站 2022-06-05 17:53:01
...

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

//此处省略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行。。。

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

windows下显示:

关于imagettftext乱码的问题

linux下显示:

关于imagettftext乱码的问题

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

回复内容:

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

//此处省略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行。。。

转码什么的都试过了,不行!也觉得不是编码的问题。。。
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服务器了。。。

相关标签: php