473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Character set problems with imagettftext

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:
http://www.mymobile.nu/services/fontgen/fonttest.php

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/';
$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);
}
?>
Jul 17 '05 #1
1 4220
On 5 Jan 2005 13:35:24 -0800, jf****@hotmail.com (Axier) wrote:
I cannot get the swedish character set on images. What can be wrong?
I would very much appreciate help.
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
hexadecimal ones.
I can supply some code here and a link:
http://www.mymobile.nu/services/fontgen/fonttest.php

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ÄÖ ";
Å 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'
(U+00C4).
# $printText = htmlentities ($printText,ENT_QUOTES, 'UTF-8');
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 Ä so you end up with that literally in your text
rather than Ä.
# $printText = utf8_encode ($printText);


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
images?

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bof | last post by:
I'm attempting to use ImageTTFText to render text to an image, I can get it to work if I a) specify the full font path b) switch off anti-aliasing c) specify an OpenType font (e.g. arial.ttf) ...
0
by: John Wellesz | last post by:
Hi, since I've upgraded to php 4.3.4 (before I used 4.1.2) I have a problem with imagettftext(): when executing the line: imagettftext($im, 20, 0, 10, 25, $white, "$script_dir/verdana.ttf",...
3
by: Leif Wessman | last post by:
From: http://www.php.net/manual/en/function.imagettftext.php "color is the color index. Using the negative of a color index has the effect of turning off antialiasing." I'm using a bundled...
0
by: ljb | last post by:
Using PHP-4.3.11 with GD extension, bundled GD library, and freetype-2.1.9 (with X.org 6.8.1). I can't get the TrueType Font (TTF) bounding box to come out right. Whether using imagettftext() or...
2
by: Gordan | last post by:
Im using imagettftext to write some text on my image. I'm on Win XP and using the plain arial.ttf font that I copied from win dir my typical line would be imagettftext($im, 33, 0, 20, 500, $black,...
1
by: binderup | last post by:
PHP 4.3.11 on Ubuntu Linux with GD2 I have compiled and installed PHP with these arguments: './configure' '--with-apxs=/www/bin/apxs' '--with-zlib' '--enable-exif' '--with-gd'...
1
by: franscescomoi | last post by:
Hi. On PHP 4.3.10 on Linux I try to: ------ $im = imagecreate(400, 30); $black = imagecolorallocate($im, 0, 0, 0); imagettftext($image, 20, -3, 10, 20, $black, 'Arial.ttf', 'Test'); ------- ...
1
by: Nitzan Tomer | last post by:
hi everyone, i created a script that outputs an image (transparent with text) based on parameters passed by $_GET. everything in my application works with 'pixels' and since GD2 this function...
3
by: =?ISO-8859-1?B?QW5kcukgSORuc2Vs?= | last post by:
Hi, I'm experiencing very bad character spacing / anti-aliasing with a PHP installation. I compared it to another installation where it works. I'm using the following test code: $ih =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.