Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- GD, IMagick and Chinese words in utf-8
May 30, 2008, 9:33 am
rate this thread
I have a problem with Chinese words coded in utf-8. I need to display
Chinese marks/words with use of GD or IMagick libs.
Chinese text that I need to display is written as plain text in .txt
file. I'm not pasting that text inside code. When I'm using only read
and echo in PHP. Everything looks fine:
<meta http-equiv="content-type" content="text/html; charset=utf-8">
Result of that script is correctly displayed text.
Problems starts when I need to display that marks in GD
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );
$image->newImage(800, 75, $pixel);
$text = file_get_contents('text/5FB4-5FFA.txt');
$draw->setFontSize( 30 );
$image->annotateImage($draw, 10, 45, 0, $text);
header ('Content-type: image/png; charset=utf-8');
Only one thing that I'm getting are "?" marks. That font is some
Chinese font in ttf, doesn't work with and without it. Quite the same
problem appears when I try to use IMagick lib.
header('Content-type: image/png; charset=utf-8');
$im = imagecreatetruecolor(400, 20);
$white = imagecolorallocate($im, 238, 238, 238);
$black = imagecolorallocate($im, 21, 21, 21);
imagefilledrectangle($im, 0, 0, 399, 29, $black);
$text = file_get_contents('text/3400-343A.txt');
$font = 'fonts/ch.ttf';
imagettftext($im, 14, 0, 10, 16, $white, $font, $text);
I'm using here the same font, and I have the same result. Only "?"
Any ideas. Where I lose my self?
Re: GD, IMagick and Chinese words in utf-8
Sebastian.Pawlus@gmail.com a écrit :
According to the name, I would say this font is specific to chinese,
still I'm asking : does it really supports chinese characters ?
Maybe the font is the problem, not truetype, or not complete... Just a
basic idea I propose.