Forum Moderators: coopster
i have a script running on my website that creates images on the fly using png backgrounds and places text on the buttons that is pulled from a database. The application that i am using it with requires multiple languages and hence i thought it would be a good idea to create the images on-the-fly.
so. here's what i'm having problems with:
the english text centers BEATUIFULLY:
then you switch to german and the text gets a little bit screwed up:
spanish a little bit as well, it mainly happens on "Office Accessories"
then finally, the italian.
could it have something to do with the special characters in the image?
here is my code for the button creation (note that this is called with variables for each instance of the button)
<?php
header("Content-type: image/png");//There are two different button types
$button = $_GET['button'];
$im = imagecreatefrompng($button.".png");//Text String
$string = $_GET['current'];$grey = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);
//Centering Algorithm
$px = (imagesx($im)- (6.5 * strlen($string))) / 2;
$font = 'arial.ttf';
//imagettftext($im, 10, 0, $px-1, 18, $grey, $font, $string);//Shaddow
imagettftext($im, 10, 0, $px, 17, $black, $font, $string);//Text
imagepng($im);
imagedestroy($im);
unset($px);
?>
Any help on this topic would be appreciated.
[edited by: jatar_k at 6:04 pm (utc) on Mar. 4, 2005]
[edit reason] removed personal urls [/edit]
I predict that the non-english characters are counting as "more than 1" which is throwing off your centering.
Why don't you use the imagettfbbox [us2.php.net] function to get the real width of the box to do your centering with? This would be better than using a fixed width for each letter when you aren't using a fixed width font. :)
Added: If you go that page, you'll see many user contributed notes which apply to your need, btw.