1

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

此文本是从 MySQL 数据库表中的排序规则设置为 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);

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

有任何想法吗?

非常感谢。

4

1 回答 1

1

使用其他字体,例如

$font = 'arial.ttf';

它工作得很好

于 2012-11-08T15:15:43.840 回答