ImageMagick / ImageMagick

🧙‍♂️ ImageMagick 7
https://imagemagick.org
Other
12.24k stars 1.36k forks source link

Text annotation with `-annotate` affects latter `-draw` positioning #6391

Open CollinHeist opened 1 year ago

CollinHeist commented 1 year ago

ImageMagick version

7.1.1-10

Operating system

MacOS

Operating system, version and so on

MacOS Ventura 13.2

Description

Translations with -annotate will affect subsequent -draw commands. I could not find anywhere that this is intended, nor how to reset these translations.

Steps to Reproduce

  1. Using some reference image, execute the following command:
    convert -size 500x500 xc:None -pointsize 50 -gravity center -fill crimson -annotate 45x45+25+25 "test" -draw "translate 250,250 path 'M -25 -25 l 50,0 0,50 -50,0 0,-50'" out.png
  2. Observe the placement and orientation of the text and SVG box.
    1. The text is drawn correctly. It is 45 degrees and 25 pixels off center.
    2. I expect the 50x50 box to be drawn relative to the center of the image, with no rotation. Instead it is rotated the 45 degrees from -annotate, and the offset is adjusted as well.

Images

out

snibgo commented 1 year ago

You have IM v7. The usual command for that is magick. But you use convert which uses the very old v6 syntax, and is provided for backwards compatability. The v7 syntax is better. I suggest using magick. (And not "magick convert" which would also use v6 syntax.)

On -gravity, see https://imagemagick.org/script/command-line-options.php#gravity :

Only the text primitive of -draw is affected by the -gravity option.

So the path is not affected by gravity.

For testing, I suggest you use a solid background like xc:Blue. A transparent background makes it hard to see what is happening.

Does that answer the question?

CollinHeist commented 1 year ago

Sorry I wasn't clear - my question was not why gravity wasn't affecting the draw, it was why the annotate repositioning (45x45+25+25 in my example) were affecting the draw path.

For reference, using the IM7 magick command creates this:

While the convert command creates this:

This doesn't seem right, as I wouldn't expect the rotation and translation to carry over. If it is intended, is there a way to reset these surface adjustments?

snibgo commented 1 year ago

The rotation from -annotate should not be carried forward to the -draw. V6 convert and v7 magick should give the same result, but they don't. This seems to be a bug in v6. For example, where I have removed "-gravity Center" for simplicity:

With IM 6.9.12-72:

convert -size 500x500 xc:Blue -pointsize 50 -fill crimson -annotate 45x45+25+25 "test" -draw "translate 250,250 path 'M -25 -25 l 50,0 0,50 -50,0 0,-50'" out6.png

out6

With IM v7.1.0-62, but using v6 syntax:

magick convert -size 500x500 xc:Blue -pointsize 50 -fill crimson -annotate 45x45+25+25 "test" -draw "translate 250,250 path 'M -25 -25 l 50,0 0,50 -50,0 0,-50'" out7b.png

out7b

With IM v7.1.0-62, using v7 syntax:

magick -size 500x500 xc:Blue -pointsize 50 -fill crimson -annotate 45x45+25+25 "test" -draw "translate 250,250 path 'M -25 -25 l 50,0 0,50 -50,0 0,-50'" out7.png

out7

The only correct result is the last one.