简体   繁体   中英

PHP - Creating image with imagettftext with Greek text

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.

Use other fonts like

$font = 'arial.ttf';

and it works just fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM