GD, IMagick and Chinese words in utf-8



Hi,
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:

example:
<?php
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<?php
echo file_get_contents('text/3400-343A.txt');
?>
</body>
</html>

Result of that script is correctly displayed text.

Problems starts when I need to display that marks in GD
example:
<?php
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );
$image->newImage(800, 75, $pixel);
$pixel->setColor('black');
$text = file_get_contents('text/5FB4-5FFA.txt');
//$draw->setFont('fonts/ch.ttf');
$draw->setFontSize( 30 );
$image->annotateImage($draw, 10, 45, 0, $text);
$image->setImageFormat('png');
header ('Content-type: image/png; charset=utf-8');
echo $image;
?>

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.

<?php
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);
imagepng($im);
imagedestroy($im);
?>

I'm using here the same font, and I have the same result. Only "?"
marks.
Any ideas. Where I lose my self?

Seba
.



Relevant Pages

  • Re: GD, IMagick and Chinese words in utf-8
    ... I have a problem with Chinese words coded in utf-8. ... Chinese text that I need to display is written as plain text in .txt ... and echo in PHP. ... Chinese font in ttf, doesn't work with and without it. ...
    (comp.lang.php)
  • Re: Object Oriented Content System - the idea
    ... >I expected php to be smarter then that. ... >form like bytecode in memory for the next request. ... each action added some stuff to a "response" XML document. ... that map/object/data and formats it for HTML display using an includeed PHP ...
    (comp.lang.php)
  • Re: session trouble
    ... Note that you're building your display block AFTER your loop. ... <?php session_start; ... The problem here is going to be since you have multiple school clubs, it's going to be hard to relate a particular club to the entry in your database if it going to be changed. ... Another way is to add a suffix to each field, often times the primary key for the table. ...
    (comp.lang.php)
  • Re: Redirecting between PHP Pages
    ... but at the very least in a php script. ... > on the outcome of the validation, you want to do one of two things: ... with the various bits of HTML being ... Display login form ...
    (comp.lang.php)
  • Re: WM5 Chinese characters
    ... The right way to do this is really to buy a Chinese device. ... The ability to display the ... If I added the font into WM5, Can I configure WM5 to output them? ...
    (microsoft.public.windowsce.embedded)