PHP 関数 imagettftext() を使用して、テキストを GIF 画像に変換しています。変換中のテキストに、日本語を含む Unicode 文字が含まれています。ローカル マシン (Ubuntu 7.10) ではすべて正常に動作しますが、Web ホスト サーバーでは日本語の文字が壊れています。違いの原因は何ですか?すべてを UTF-8 でエンコードする必要があります。
ウェブホスト サーバー上の壊れた画像: http://www.ibeni.net/flashcards/imagetest.php
ローカル マシンからの正しい画像のコピー: http://www.ibeni.net/flashcards/imagetest.php.gif
私のローカル マシンからの phpinfo() のコピー: http://www.ibeni.net/flashcards/phpinfo.php.html
ウェブホスト サーバーからの phpinfo() のコピー: http://example5.nfshost.com/phpinfo
コード:
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);