By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

GD, IMagick and Chinese words in utf-8

P: n/a
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
Jun 2 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Se**************@gmail.com a écrit :
$font = 'fonts/ch.ttf';
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.

Regards,
--
Guillaume
Jun 2 '08 #2

P: n/a

Guillaume, great TIP.
Fonts were Chinese but that what I want display was over the scope of
my current fonts.

I've downloaded Chinese fonts from http://www.wazu.jp/gallery/Fonts_Chi...aditional.html.

Thanks
Seba

Jun 2 '08 #3

P: n/a

Guillaume, great TIP.
Fonts were Chinese but that what I want display was over the scope of
my current fonts.

I've downloaded Chinese fonts from http://www.wazu.jp/gallery/Fonts_Chi...aditional.html.

Thanks
Seba

Jun 2 '08 #4

P: n/a
On May 30, 9:33 pm, Sebastian.Paw...@gmail.com wrote:
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
is your browser/OS support display chinese font?
Jun 2 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.