rc69, on Jul 1 2006, 06:24 AM, said:
The only solution i've ever found to that, is to count the characters, do some math, and make a best guess for the position of the first character. I never got it to work 100% for some reason, but it basically went like:
i's, l's, !'s, took up one pixel.
Everything else took up 4.
There was 2 pixels of space between the characters, with 4 pixels for a space.
Count the i's, l's, and !'s, multiply by 1, count remaing characters, multiply by 4, add together... blah blah blah... Got a semi-right aligned text, but it wasn't perfect (give or take 8px's on each line).
yeh thats basically what i did, i made an example using the maxium string which was 88888 and i used some functions in php to determine the maximum string length in pixels, then i figured out the length of the string 8888 and figured out the difference in string length and the difference in the position of the string and i was able to compensate... yeh very confusing
this is what i used to figure out the string width and string x position...
$string_width = imagefontwidth($font1)*strlen($text2);
$string_x_position = ($image_width-$string_width)/2;
so i knew the string width and x position of the maximum string and then compared it to a smaller string and found that for every 1 pixel difference in string width there was a 0.5 difference in x position, i noticed u said ur method wouldnt work 100% of the time, mine seems too i hope this helps you out
Edited by BlazeForc3, 02 July 2006 - 01:48 PM.