PHP - 使用希腊文本的imagettftext创建图像

时间:2012-07-10 15:18:22

标签: php internationalization imagettftext

我正在尝试使用imagettftext使用希腊文“απότον/την”创建图像。

从一个字段中读取此文本,该字段的排序规则设置为utf8-unicode-ci。

文本出来的数据库为“΀ÏÏϔον/ϓην”。

这是代码(取自php.net)

header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = html_entity_decode('από τον/την', ENT_COMPAT, 'UTF-8');

// Replace path by your own font path
$font = '/Applications/MAMP/htdocs/test.localhost/libs/fonts/CustomFont.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);

这会产生一个带有“΀όϔον/ϓην”而不是“απότον/την”的图像。

有什么想法吗?

非常感谢。

1 个答案:

答案 0 :(得分:1)

使用其他字体,例如

$font = 'arial.ttf';

它运作得很好