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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
subhendu
Forum Newbie
Posts: 2
Joined: Fri Jul 07, 2006 12:51 am

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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply