Page 1 of 1

Anyway to counteract -kerning not being proportional when changing font size?

Posted: 2016-04-15T13:44:34-07:00
by FriendlyFriend
Image
https://i.imgur.com/XXRgtbP.png

These are thumbnails of Image Magick created images.
Just putting out text "AB" "-kerning -10" and incrementing font size by 5pt from 31 to 231pt.

Notice how at smaller sizes A & B are overlapping strongly and progressively less so as you get to larger font sizes?

Can anyone explain why or does anyone have any ideas how to counteract it? I spit out widths etc and I'm having trouble thinking of a formula.

In the end I already have an app using this and the user can choose point size and spacing amount.
BUT... the users can't handle that the spacing amount is not linear as shown above... and to be honest it's off putting when I use it.

I suppose I could make all text at 120pt and resize it down but that seems messy, looks ugly, and just sounds like a poor solution.

Command:

Code: Select all

convert -pointsize 31 -kerning -10 -font Arial -background white -fill "#848484" label:"AB" "ARIAL_31pt_0_-10k.jpg"
[increment "31" by 5 for each additional image]

This was ImageMagick Windows command line version 6.6.5 - does it in 6.9.3 as well and I'm 99% sure it's doing it in Linux. Tried a couple typefaces.

Re: Anyway to counteract -kerning not being proportional when changing font size?

Posted: 2016-04-15T17:19:18-07:00
by snibgo
"-kerning", like "-pointsize", is in absolute units. They are not relative to each other. For your application, you might give the user the option to specify kerning as a proportion of the pointsize, for example "-10%". Your application will do the maths. Then varying pointsize will give results that look the same, but scaled.

Re: Anyway to counteract -kerning not being proportional when changing font size?

Posted: 2016-04-15T18:22:33-07:00
by GeeMack
FriendlyFriend wrote:Can anyone explain why or does anyone have any ideas how to counteract it? I spit out widths etc and I'm having trouble thinking of a formula.
The "-kerning" setting in IM is the number of pixels added (or subtracted) between each character in the text. To do what you want you'd have to set a "-kerning" value to a number that is somehow relative to the "-pointsize" value.

I'm using ImageMagick 7 (ImageMagick 7.0.0-0 Q16 x64 2016-04-10), which allows for some FX calculations directly in the command in places that won't work with IM6, but the example below might give you an idea where to start. In a batch file using Windows 7 64, I set a variable for the pointsize, %POINTS%, and another variable for the kerning, %KERN%. This %KERN% variable is used inside the IM command to calculate a value which becomes self adjusting to be proportional to the pointsize.

This works for me in a Windows batch script. When I double the %POINTS% value, for example, the output text is twice as large while maintaining the relative kerning. Increasing or decreasing the %KERN% value changes the spacing between characters. Setting %KERN% to zero leaves the kerning at IM's "-kerning 0". It can use negative values to condense the space between characters, too.

Code: Select all

set POINTS=128
set KERN=5

magick ^
   -gravity center ^
   -size 600x200 ^
   canvas:white ^
   -pointsize %POINTS% ^
   -kerning %%[fx:%POINTS%*(%KERN%*0.05)] ^
   -annotate +0+0 "ABCDEF" ^
      result.png
If you're not using IM7, that FX calculation will have to be done in the script ahead of the IM command, then included as a variable within the command. That will probably require building the script in something like PowerShell or Javascript because Windows' standard cmd.exe is pretty weak on doing calculations.