Using gravity setting with label:

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Using gravity setting with label:

Post by GeeMack »

This is an extension of a conversation found at THIS link in the Users section. Using IM 7.0.3-9 on Windows 10 64, when I generate a label image with a setting of "-gravity center" (and most others), a few pixels get clipped off the first character at left edge of the image. Here is a command to create two sample images, one without a "-gravity" setting and the other set to "center"...

Code: Select all

magick -pointsize 96 label:"A LABEL!" -gravity center label:"A LABEL!" test%0d.png
That outputs these two PNG files...

Image

Image

The second example there shows how that left side gets pushed out of the viewport. This will occur with the default font or with several other common Windows fonts I've tested. It occurs at any pointsize, but the results are more obvious with a larger size like I used for the examples.

The problem is more pronounced when the label text ends with an exclamation point, colon, or pipe, or other tall narrow characters, but is also evident when ending with normal letter/number characters.

A suggestion was made in the opening conversation to escape the exclamation point with a caret or backslash, but neither seem to affect the results.

Different gravity settings may change the results by a few pixels, but when using most settings the problem persists. And although gravity wouldn't generally be a concern when creating a label, it's not uncommon to have a particular gravity setting come before a label in a command for other reasons.

After testing this a variety of ways with different fonts and sizes, the results lead me to believe this is a bug.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using gravity setting with label:

Post by fmw42 »

I can reproduce on my Mac OSX in IM 7.0.3.9 Q16.

Code: Select all

magick -pointsize 96 label:"A LABEL\!" -gravity center label:"A LABEL\!" tmp_%d.png
But on unix, I think you have to escape the !. I get an error message without it.

Code: Select all

-bash: !": event not found
P.S. You can use +gravity to turn off centering such as where I reverse the order above:

Code: Select all

magick -pointsize 96 -gravity center label:"A LABEL\!" +gravity label:"A LABEL\!" tmp_%d.png
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Using gravity setting with label:

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
Post Reply