PHP-使用带有希腊文本的imagettftext创建图像 [英] PHP - Creating image with imagettftext with Greek text
本文介绍了PHP-使用带有希腊文本的imagettftext创建图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用imagettftext使用此希腊文字απότον/την"创建图像.
I'm trying to use imagettftext to create an image using this Greek text "από τον/την".
从MySQL数据库表的排序规则设置为utf8-unicode-ci的字段中读取此文本.
This text is read from a MySQL database table from a field whose collation is set to utf8-unicode-ci.
文本从数据库中出来为α-β/β/α-β".
The text comes out of the database as "από τον/την".
这是代码(从php.net提取)
Here's the code (lifted from 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);
这会产生带有απόταγ/γαβ"而不是απότον/την"的图像.
This produces an image with "από τον/την" and not "από τον/την".
有什么想法吗?
非常感谢.
推荐答案
使用其他字体,例如
$font = 'arial.ttf';
它很好用
这篇关于PHP-使用带有希腊文本的imagettftext创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文