Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP function imagettftext() and unicode
    text
    copied!<p>I'm using the PHP function imagettftext() to convert text into a GIF image. The text I am converting has Unicode characters including Japanese. Everything works fine on my local machine (Ubuntu 7.10), but on my webhost server, the Japanese characters are mangled. What could be causing the difference? Everything should be encoded as UTF-8.</p> <p>Broken Image on webhost server: <a href="http://www.ibeni.net/flashcards/imagetest.php" rel="noreferrer">http://www.ibeni.net/flashcards/imagetest.php</a></p> <p>Copy of correct image from my local machine: <a href="http://www.ibeni.net/flashcards/imagetest.php.gif" rel="noreferrer">http://www.ibeni.net/flashcards/imagetest.php.gif</a></p> <p>Copy of phpinfo() from my local machine: <a href="http://www.ibeni.net/flashcards/phpinfo.php.html" rel="noreferrer">http://www.ibeni.net/flashcards/phpinfo.php.html</a></p> <p>Copy of phpinfo() from my webhost server: <a href="http://example5.nfshost.com/phpinfo" rel="noreferrer">http://example5.nfshost.com/phpinfo</a></p> <p>Code:</p> <pre><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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload