Hi guyz,
I was wondering if you also had problems with the function imagettfbbox(). I'm trying to calculate the width of a given text, so i can determine wether i need more lines / tablerows to put the text in.
However i can't seem to find the proper code snippet for this purpose. It seems that the imagettfbbox isn't very accurate (or is it me?) in determining the widht of a given text. For instance: when i imagettfbbox this: 29-11-2005 (font: Trebuchet MS 12 px) then the width of the bounding box returned is 74 ($bbox[2]+$bbox[0], however when i watch the same text in adobe then the width is about 58 pixels. That last one seems about correct since my table with is set to 65.
Is there any way to determine exactly how many pixels my text is?
I've been doing a lot of searching however didn't come up with anything..
I'm adding the right x value since it is starting at -1, so basiccally if i subtract it then my total value goes up.. I'll have a go and see if i'm using 12 px or 12pt, hope i can get it right since it'll save me a lot of time if i have to come up with a routine myself.. LOL..
Thanks feyd i'll have a look in the px and pt values..
As far as I can tell, imagettfbbox() is perfectly correct for what imagettftext() draws.. but thats not the same as you'll be drawing in Photoshop. Photoshop has a much more advanced font renderer than the Freetype library, it can mess about with the kerning, hinting, letter spacing and more.
Trying to get PHP to draw text in the same way Photoshop does is a bit of a nightmare.
Heheheh... What i did was alt-prtscrn and paste it into photoshop, however since my td width is about 65 pixels and imagettfbbox calculates a position of right: -1 and left: 77, i cant use the imagttfbbox routine to calculate the max nr. of pixels.
I did do some more reading and saw that an earlier gd library worked with pixels and that the upgrade (i believe 2.x) is working with points, so i think feyd is right and that my problem is lying in the point/pixel difference...
So now i'm trying to figure out if there is a general rule for points to pixel conversion.. Hopefully i find it, cause i think that's where my problem is and the gdlib i have is working with points while my css stylesheet is in pixels..
from what I remember, 72pt = 1" on a given display. Since most monitors are 72dpi, then 1pt should be about 1px. In practice it is not however, due to the rendering engine of the browser among other things. Most OS's don't have very good font rendering, so kerning and other things may be wonky on some machines.
I'd just suggest redesigning the page to allow for varying font sizes..
Thanks for the info feyd.. I haven't found the right routine yet, so i basically designed a preview screen to view the text and then approve it by setting the number of lines the message is.
It's not a very nifty solution, but it does work.. I'll keep looking though...