I'm trying to adequate the FontSize of my text into a width-height specific context. For instance, if I got a image (512x512 pixels) and I got for instance 140 characters. What would be the ideal FontSize? 
In the above case, a 50 pixels Fontsize seems to be ok but what happened if there's a lot more text? the text will not fit into the picture so it needs reduction. I've been trying to calculate this on my own without success.
What I've tried is this:
get total pixels, with a picture 512x512 = 262144 and divide into the length of the text. But that gives a big number. Even if I divided that number by 4 (thinking about a box-pixel-model for the font).
Do you have any solutions for this?
PS. I've been using truetype (if this is somehow useful)
I've been using python for this purpose, and PIL for image manipulation.
Thank you in advance.
It's pretty tricky to do analytically.
One way is trial and error. Choose a large font size and render the layout to see whether it fits
Use bisection algorithm to converge on the largest font that fits
Calculate fontsize