Re: [GD-DEVEL] unicode chinese text to pict

[email protected] (Pierre)
Newsgroups php.gd.devel
Message-ID <[email protected]>
Hi,

On 5/24/07, ZeFiF <[email protected]> wrote:

> maybe you are francophone as I am :-)

Je suis francophone :)

I will continue in english and using the mailing lists, other people
may be interested and it may help the archives readers :)

> here is the script

See my slightly modified script as attachment. It works the same way
for the TTF parts but the PNG images uses alpha for the antialiasing,
looks nicer on custom background :)


> Thank you to take care of my problem...

The attached image shows what I got using the wt001.ttf fonts ( from
http://apt.nc.hcc.edu.tw/pub/FreeSoftware/free_fonts/wangttf/ right?).
Is it what you expect?

--Pierre
chinese.php (application/x-php, 784 B)
<?php
// Set the content-type
header("Content-type: image/png");

$fontsize = 18;
$font = './wt001.ttf';
$text = '金人月';

// Create the image
$size = imagettfbbox($fontsize, 0, $font, $text);
$width = $size[2] + $size[0] + 8;
$height = abs($size[1]) + abs($size[7]);

$im = imagecreatetruecolor($width, $height);
imagealphablending($im, false);
imagefilledrectangle($im, 0,0, $width, $height, imagecolorallocatealpha($im, 255,255,255,127));

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// Add the text
imagefttext($im, $fontsize, 0, 0, abs($size[5]), $black, $font, $text);
imagesavealpha($im, true);
// Using imagepng() results in clearer text compared with
imagepng($im, "chinese.png");
imagedestroy($im);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.