问题
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