Character set problems with imagettftext

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I cannot get the swedish character set on images. What can be wrong?
I would very much appreciate help.

regards, axier

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&#196;Í ";
# $printText = htmlentities ($printText,ENT_QUOTES, 'UTF-8');
# $printText = utf8_encode ($printText);
$convertExec = "/usr/bin/convert";

$thisDir = '/fonts/';
$thisFont ='arial.ttf';
echo "$thisFont<br>";

for($i=$startsize;$i<$sizes;$i++) {
    $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);
    ImagePng ($im,'test'.$i.'.png');
    echo $i.' <img src="test'.$i.'.png"><br>';
    ImageDestroy ($im);

Re: Character set problems with imagettftext

On 5 Jan 2005 13:35:24 -0800, (Axier) wrote:

Quoted text here. Click to load it

 I submitted a documentation bug not long ago
( ) 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
hexadecimal ones.

Quoted text here. Click to load it

 ┼ 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.

 &#196; looks better though, that's 'LATIN CAPITAL LETTER A WITH DIAERESIS'

Quoted text here. Click to load it

 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
it's not.

 And it'll escape the &#196; so you end up with that literally in your text
rather than ─.

Quoted text here. Click to load it

 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 &#196; in the

< Space: disk usage analysis tool

Site Timeline