note 75493 added to function.imagettftext
| From: | php at gilbertson dot me dot uk | Date: | Fri, 01 Jun 2007 20:52:32 +0000 |
| Subject: | note 75493 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127110@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 194.145.210.4
Probable Submitter: 217.155.222.46
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- https://master.php.net/note/edit/75493
Del: integrated -- https://master.php.net/note/delete/75493/integrated
Del: useless -- https://master.php.net/note/delete/75493/useless
Del: bad code -- https://master.php.net/note/delete/75493/bad+code
Del: spam -- https://master.php.net/note/delete/75493/spam
Del: non-english -- https://master.php.net/note/delete/75493/non-english
Del: in docs -- https://master.php.net/note/delete/75493/in+docs
Del: other reasons-- https://master.php.net/note/delete/75493
Reject -- https://master.php.net/note/reject/75493
Search -- https://master.php.net/manage/user-notes.php