【问题标题】:PHP - Creating image with imagettftext with Greek textPHP - 使用带有希腊文本的 imagettftext 创建图像
【发布时间】:2012-07-10 15:18:21
【问题描述】:

我正在尝试使用 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);

这会生成带有“από τον/την”的图像。

有什么想法吗?

非常感谢。

【问题讨论】:

  • 你直接从数据库试过了吗?
  • 是的,当从数据库中读取时,它会显示为这个字符串“από τον/την”,这是我插入到 html_entity_decode 中的内容跨度>
  • 我的意思是不打印出来,浏览器/操作系统有时会搞砸编码。
  • 哦,对了。当我在代码中执行 $text = "από τον/την" 时,结果是正确的。问题是我需要从数据库中读取它。谢谢!
  • 我的意思是,当您从数据库中打印出来时,您在 yoru 操作系统/浏览器上的本地编码可能会出错。您是否从数据库中直接尝试过?

标签: php internationalization imagettftext


【解决方案1】:

使用其他字体,例如

$font = 'arial.ttf';

而且效果很好

【讨论】:

    猜你喜欢
    • 2012-04-20
    • 2011-01-27
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多