Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Character set problems with imagettftext
January 5, 2005, 7:35 pm
rate this thread
I would very much appreciate help.
I can supply some code here and a link:
Some people looks like they can get it to work with no effort at all
with the same script.
The code looks like this:
setlocale (LC_ALL, 'swedish');
$sizes = 10;
$startsize = 6;
$printText = "A B C D E F G H ABCDEFGH AOU┼ EIYÄÍ ";
# $printText = htmlentities ($printText,ENT_QUOTES, 'UTF-8');
# $printText = utf8_encode ($printText);
$convertExec = "/usr/bin/convert";
$thisDir = '/fonts/';
$im = imagecreate (400, 30);
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
ImageTTFText ($im, $i , 0, 10, 20, -$white, $thisDir.$thisFont, $printText);
echo $i.' <img src="test'.$i.'.png"><br>';
Re: Character set problems with imagettftext
I submitted a documentation bug not long ago
(http://bugs.php.net/bug.php?id=30801 ) against the imagettftext function as the
text parameter's description was wrong. Just checked the page and it looks like
the latest update has now been put on the PHP site.
The main points are:
(1) The text parameter requires UTF8 encoding.
(2) It only accepts decimal numeric character entities; not named ones nor
┼ isn't valid UTF8 so you're potentially in trouble there to start with. That
character is 0xC5; in binary it's 11000101 so it looks like the lead byte of a
two-byte character. The next byte is a space, which isn't a valid trail byte,
so you've got an invalid string there from the point of view of imagettftext.
Having said that, it looks like it has a go at interpreting as
ISO-8859-something when it hits invalid UTF-8.
Ä looks better though, that's 'LATIN CAPITAL LETTER A WITH DIAERESIS'
htmlentities will convert to named entities, which imagettftext doesn't
accept, and additionally you're claiming the string is UTF-8 in this call when
And it'll escape the Ä so you end up with that literally in your text
rather than ─.
OK, perhaps along the right lines to get the literal ┼ working...
In fact the code you posted gives the results I'd expect when I run it on PHP
5.0.3 on Windows. Haven't tried it on Unix though as it looks like I've not
compiled TTF support into my test machine's PHP.
Are you running the same code? Looks like you may have uncommented some of the
lines you have commented in your post as you've got the literal Ä in the
<http://www.andyhsoftware.co.uk/space Space: disk usage analysis tool