1
我正在尝试使用imagettftext来创建一个使用希腊文字“απότον/την”的图像。PHP - 使用希腊文字创建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);
这产生了“αI€IOE I“的图像ον/ I“I·Î½" 的代码,而不是“απότον/ την”。
任何想法?
非常感谢。
你有没有直接从数据库中尝试过吗? – 2012-07-10 15:21:40
是的,从数据库读取时,它出现为这个字符串“我希望我的”我的/我的“我的”,这就是我插入html_entity_decode – Shmoyko 2012-07-10 15:34:41
我的意思是没有打印出来,浏览器/ os的有时可能会搞砸编码。 – 2012-07-11 12:09:54