Appending text and interline-spacing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sidewinder
Posts: 2
Joined: 2014-10-08T14:30:15-07:00
Authentication code: 6789

Appending text and interline-spacing

Post by sidewinder »

Hello!

I'm having some trouble understanding creating texts with ImageMagick, more specificaly with the space between each line. I want to create texts and know beforehand what the height of the texts will be, I do not get this to work.

I'm running the following command:
convert -gravity Center -size 56x704 xc:none -font "Verdana" -density 72 -pointsize 88 -fill green -annotate 0 "1\n2\n3\n4\n5\n6\n7\n8" text.jpg

This will create a text with 8 lines, 8x88 = 704 so I expect the text to perfectly fill the image, however there seems to be to much space between each line and the text does not fit, it is to large.

After some testing I found out that if I reduce the -interline-spacing by 0.2 times the fontsize the text seems to pit perfectly:
convert -gravity Center -size 56x704 xc:none -font "Verdana" -density 72 -pointsize 88 -interline-spacing -17.6 -fill green -annotate 0 "1\n2\n3\n4\n5\n6\n7\n8" text.jpg

In addition there also seems to be different from font to font, for example for Times New Roman the proper value seems to be 0.1 * font size.

Any ideas what I'm missing?
My enviroment is running ImageMagick-6.8.8-Q16 under Windows7
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Appending text and interline-spacing

Post by fmw42 »

I am not a font expert. But you are missing nothing to the best of my understanding. Each font has its own set of metrics that define font size and other characteristics. Each newline \n creates a new line of the given font characteristics for a blank. Interline spacing adjusts/overrides that.

I am not sure pointsize is always the same as pixels (unless you specify density at 72 dpi). See http://graphicdesign.stackexchange.com/ ... difference

You can see the font metrics by following:
http://www.imagemagick.org/Usage/text/#font_info

Perhaps some one more knowledgable than I about fonts and their metrics can answer better.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Appending text and interline-spacing

Post by snibgo »

I know almost nothing about font metrics (see http://www.imagemagick.org/Usage/text/#font_info ) but "-debug annotate" in your command shows a height of 107, which seems to be the actual line spacing used, in pixels.
snibgo's IM pages: im.snibgo.com
sidewinder
Posts: 2
Joined: 2014-10-08T14:30:15-07:00
Authentication code: 6789

Re: Appending text and interline-spacing

Post by sidewinder »

So, there is a possibility here that I miss understand something fundamental.

I my mind a fontsize of 88 means that each row is 88 pixels, next row is also 88 pixels and those 88 pixels each include the spacing over and below the lines. This makes sense to me since not all fonts have the same height of the letters even with the same font size.

But looking at how Imagemagic seems to handle this, a text with fontsize 88 is 88 pixels per row + a spacing that is different from each font. Setting a interline-spacing adds or subtracts to this already set spacing. Setting this to 0 keeps the already set space.

So my real question then is, how can I either find out the already set spacing for each font, or alternatively set this spacing to 0 no matter what font I use and make sure that the line actually is 88 pixels high.
Post Reply