我正在使用 PHP 函数 imagettftext() 将文本转换为 GIF 图像。我正在转换的文本包含 Unicode 字符,包括日语。在我的本地计算机(Ubuntu 7.10)上一切正常,但在我的网络主机服务器上,日语字符被破坏。是什么导致了这种差异?所有内容均应编码为 UTF-8。
虚拟主机服务器上的图像损坏:http://www.ibeni.net/flashcards/imagetest.php http://www.ibeni.net/flashcards/imagetest.php
从我的本地计算机复制正确的图像:http://www.ibeni.net/flashcards/imagetest.php.gif http://www.ibeni.net/flashcards/imagetest.php.gif
从我的本地计算机复制 phpinfo() :http://www.ibeni.net/flashcards/phpinfo.php.html http://www.ibeni.net/flashcards/phpinfo.php.html
从我的虚拟主机服务器复制 phpinfo() :http://example5.nfshost.com/phpinfo http://example5.nfshost.com/phpinfo
Code:
mb_language('uni');
mb_internal_encoding('UTF-8');
header('Content-type: image/gif');
$text = '日本語';
$font = './Cyberbit.ttf';
// Create the image
$im = imagecreatetruecolor(160, 160);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// Create some colors
imagefilledrectangle($im, 0, 0, 159, 159, $white);
// Add the text
imagettftext($im, 12, 0, 20, 20, $black, $font, $text);
imagegif($im);
imagedestroy($im);