PHP - Creating image with imagettftext with Greek text

…衆ロ難τιáo~ 提交于 2019-12-24 17:53:37

问题


I'm trying to use imagettftext to create an image using this Greek text "από τον/την".

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 "από τον/την".

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 "από τον/την".

Any ideas?

Many thanks.


回答1:


Use other fonts like

$font = 'arial.ttf';

and it works just fine



来源:https://stackoverflow.com/questions/11416546/php-creating-image-with-imagettftext-with-greek-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!