How to annotate with largest font size possible when given a height of a (blank) image?
I'm using PHP/imagemagick to annotate an image. But I have a constraint of how big the font can be.
for example... given the text string "hello world", font "courier", and a height of 150px, how do I create a transparent background PNG with height 150x that has the largest font size开发者_JAVA百科 possible with text "hello world" in courier?
Is there a way to do this w/o incrementally "testing" to see if the font is too big?
Not really since the letter kerning of every font is unique and can even vary on different operating systems.
Using a monospaced font might make it predictable enough to guess the right width but thats probably not an option...
You need to get the width of the font. You can use imagefontwidth($font) to do this. If you look through the comments you will an example of someone trying to get a width of text.
精彩评论