note 75493 deleted from function.imagettftext by cmb
| From: | cmb@php.net | Date: | Sun, 13 Jan 2019 10:40:59 +0000 |
| Subject: | note 75493 deleted from function.imagettftext by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210048@lists.php.net to get a copy of this message | ||
Note Submitter: php at gilbertson dot me dot uk
----
Users may note a problem trying to use this function to display the Euro symbol.
The reason is that it is a late addition. Although the operating systems generally recognise code
0x80 (128 decimal) as Euro, this is not where it necessarily appears in the font. Some have it
there, but many just have it in the extended character set at position 0x20AC (8364 decimal).
I have yet to find a font with it only at 0x80, so here is the fix:
<?php
$image=imagecreate(135,24);
$bg=imagecolorallocate($image,0,0,0);
$fg=imagecolorallocate($image,0,255,0);
$text = 'coffee - â¬3.50';
$friendly = eurofix($text);
imagettftext($image,16,0,5,20,$fg,"Papyrus.ttf",$friendly);
imagegif ($image);
imagedestroy ($image);
function eurofix($str) {
$euro=utf8_encode('€');
$str = preg_replace('/\x80/',$euro,$str);
return ($str);
}
?>
You should note, however, this won't help with fonts older than about 1999. It can only make
sure the Euro is displayed where available.