GD, IMagick and Chinese words in utf-8
- From: Sebastian.Pawlus@xxxxxxxxx
- Date: Fri, 30 May 2008 02:33:29 -0700 (PDT)
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
.
- Follow-Ups:
- Re: GD, IMagick and Chinese words in utf-8
- From: ctx2002
- Re: GD, IMagick and Chinese words in utf-8
- From: Guillaume
- Re: GD, IMagick and Chinese words in utf-8
- Prev by Date: Re: validating # sign in php
- Next by Date: Re: GD, IMagick and Chinese words in utf-8
- Previous by thread: Re: More than 500 free webhostings
- Next by thread: Re: GD, IMagick and Chinese words in utf-8
- Index(es):
Relevant Pages
|