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.
Select font size to fit a string in a given rectangle?
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.