-
imagettftext
Hey,
Ok I'm drawing some text onto an image using imagettftext, (The text is at an angle) and we have a fixed area the text can go into, the user can input between 1 and 25 characters. The more characters they put in the smaller the text needs to be. How can I get the character width of a ttf font at a certain size (and ideally per character because 'I' will be smaller than 'W')
Thanks
-
Re: imagettftext
well, you could use imagefontwidth(); but you'll need to use it in conjunction with imageloadfont(), and you'll need a GDF font file, and you'll need to be using imagestring() rather than imagettftext() (and imagestring() does not support rotation as far as I recall)!
but, if you want to stick with true type fonts, you could alternatively try using imagettfbbox() to create the bounding box of the text you're creating, and then scale it down depending on where that lands?
edit: I was doing some testing, and imagefontwidth() will respond to a path to a TTF file. however, when using it on Arial, I got a return value of 5 (which could just be the maximum width of any character, though I have no idea what font size it was!); now, how useful this might be to you, I'm not sure. and I haven't even used it on another file so it could just not be returning correctly at all! I'm really not sure. either way, even the "solution" I gave you about that loads a font and uses imagestring() probably wouldn't be very useful at all. try the bounding box, maybe! /ramble-off.