Page 1 of 1

Select font size to fit a string in a given rectangle?

Posted: Fri Jul 07, 2006 1:09 am
by subhendu
How do I choose a font size to exactly fit a string in a given rectangle?

I have a background image (the size of this image can change), and I need to put some text in this piece of image. Depending upon the background image, the font size needs to be adjusted.

Thanks.

Posted: Fri Jul 07, 2006 1:25 am
by feyd
You'd have to calculate the required box needed for the given text in each size. imagettfbbox() and its siblings can tell you this information.