Calculating the correct font size based on an amount of pixels
Posted: 2019-01-28T02:32:19-07:00
Hello Community,
is there a way to calculate the font size depending on a given amount of pixels?
Example: I draw text on 5 different images. The words drawen have different amount of characters. Some 3 long, some 12.
Right now I have a variable $FONTSIZE where I substract the amount of characters*10. Simply means: Longer words get a smaller $FONTSIZE.
Problem: This works with words till 9 character, but not for 12 or even longer. In total longer words get too small.
So I asked myself, is there a way to tell ImageMagick an amout of pixels like 300 and is calculates the best fontsize like: Ok 300 pixel, word to draw 4 letters, fitting fontsize = 130
Thank you very much and have a nice day.
Jens
is there a way to calculate the font size depending on a given amount of pixels?
Example: I draw text on 5 different images. The words drawen have different amount of characters. Some 3 long, some 12.
Right now I have a variable $FONTSIZE where I substract the amount of characters*10. Simply means: Longer words get a smaller $FONTSIZE.
Problem: This works with words till 9 character, but not for 12 or even longer. In total longer words get too small.
So I asked myself, is there a way to tell ImageMagick an amout of pixels like 300 and is calculates the best fontsize like: Ok 300 pixel, word to draw 4 letters, fitting fontsize = 130
Thank you very much and have a nice day.
Jens