开发者

How to annotate with largest font size possible when given a height of a (blank) image?

开发者 https://www.devze.com 2023-03-28 19:36 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号