Different results for label and annotate/draw (maybe bug in IM)

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
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Different results for label and annotate/draw (maybe bug in IM)

Post by rotem »

Hey,

I'm using a font called grobold (https://drive.google.com/file/d/0B3Czzl ... sp=sharing)

When using label with this command

Code: Select all

convert -background none -debug annotate "-font" "./assets/grobold.ttf" -pointsize 35 label:'!' -trim -write info: x.png
this is the result (29px height)

Image

and when using annotate/draw with this command

Code: Select all

convert -size 400x400 -background none xc:none "-font" "./assets/grobold.ttf" -pointsize 35 -annotate +200+200 '\!' -trim +write info: x.png
this is the result (34px height)

Image

Is that a bug? what am I doing wrong?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by snibgo »

"-trim" should usually be followed by "+repage".

"label:" automatically chooses a canvas size based on font metrics. For some fonts, glyphs can exceed these boundaries. Try it with:

Code: Select all

label:'\n ! \n'
snibgo's IM pages: im.snibgo.com
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by rotem »

Cool snibgo, it's working. However, I also need to use the output in order to get the font's boundaries.

For example, this output will allow me to understand that this character have 7px boundary from top 1px from the right, and 8px from the bottom.

Code: Select all

label:a LABEL 21x21 22x36+0+7
If I use your method the output would be very different.

Do you have any other idea what can I do?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by snibgo »

So you would want negative numbers where the glyph exceeds the boundaries given by the font metrics? Then I think you need to parse the font metrics, but I don't know much about that.
snibgo's IM pages: im.snibgo.com
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by rotem »

How do I get the font metrics?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by snibgo »

From your first command. The text output will include something like:

Code: Select all

  Metrics: text: '!'; width: 22.4688; height: 40; ascent: 32; descent: -7; max advance: 70; bounds: 1.53125,0  6.8125,26; origin: 24,0; pixels per em: 35,35; underline position: -4.5625; underline thickness: 2.34375
snibgo's IM pages: im.snibgo.com
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by rotem »

oh, yeah I'm reading them metrics. I also don't know how to parse them.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by fmw42 »

What is your IM version and platform? Please always provide that since IM syntax and scripting can be different.

Please read the top-most post in this forum at viewtopic.php?f=1&t=9620
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by rotem »

Hey fmw42,

as I understand this is not a bug because what snibgo said:
"label:" automatically chooses a canvas size based on font metrics. For some fonts, glyphs can exceed these boundaries.
right?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by fmw42 »

Yes. But my point was that windows and unix syntax may differ (especially for scripting) and issues may occur because of different IM versions. So it is always a good idea to provid yur IM version and platform. You said you did not know how to parse the font metric. That would need some OS scripting which would be different depending upon your OS (Windows vs Unix). So we need to know this information since we all do not script in both Unix and Windows. So different people might need to help you parse that.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by snibgo »

snibgo wrote:Then I think you need to parse the font metrics, but I don't know much about that.
To clarify: syntactic parsing is easy enough. In Windows, just use a FOR loop with appropriate tokens, delims etc. But I don't know much about what the numbers actually mean. See http://www.imagemagick.org/Usage/text/#font_info
snibgo's IM pages: im.snibgo.com
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by rotem »

fmw42, yeah I understand what you mean and from now on I will add my OS and IM version. However, my question was about what the number actually means (just like snibgo said in the last comment). Sorry for not being clear enough.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by fmw42 »

the diagram at http://www.imagemagick.org/Usage/text/#font_info is all I know for such information
rotem
Posts: 46
Joined: 2016-04-15T13:34:32-07:00
Authentication code: 1151

Re: Different results for label and annotate/draw (maybe bug in IM)

Post by rotem »

Yeah, well as one that spent a lot of time investigating font metrics I can tell you that I couldn't find anyway to corollate the diagram with the -debug annotate output.
Post Reply