Page 1 of 1

[Resolved]-annotate silently fails on some images

Posted: 2019-12-01T15:04:49-07:00
by user001
The -annotate option to the magick/convert commands silently fails on some input images.

This was found to occur with both of the following IM versions:

Code: Select all

$ convert --version | head -n1
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
$ magick --version | head -n1
Version: ImageMagick 7.0.9-8 Q64 x86_64 2019-12-01 https://imagemagick.org
The following command produces an image containing the expected annotation:

Code: Select all

$ magick 'xc:black[1x1!]' -resize 100x -gravity east -splice 100x0 -fill black -pointsize 36 -annotate "+0+0" "test" x:
Substituting an image in place of the xc: canvas results in the appearance of text for most images. However, for some images, no text appears. An example image is this 1x1 pixel image:

Code: Select all

$ magick a.png -resize 100x -gravity east -splice 100x0 -fill black -pointsize 36 -annotate "+0+0" "test" x:
As this board does not appear to support attachments, please let me know where I can send/post the image from this example. Thanks.

Re: -annotate silently fails on some images

Posted: 2019-12-01T15:45:31-07:00
by GeeMack
user001 wrote:
2019-12-01T15:04:49-07:00
Substituting an image in place of the xc: canvas results in the appearance of text for most images. However, for some images, no text appears.
I suspect some of your input images contain some page geometry, and that makes your "-annotate" place the text outside the visible canvas. Try adding "+repage" before the "-annotate" operation.

Code: Select all

$ magick a.png -resize 100x -gravity east -splice 100x0 -fill black -pointsize 36 +repage -annotate "+0+0" "test" x:

Re: -annotate silently fails on some images

Posted: 2019-12-01T17:11:04-07:00
by user001
Thanks GeeMack, your suspicion was correct. Why does the page geometry affect text placement but not the splice operation? That is, the splice occurred in the place expected (immediately to the right of the image), while the font was presumably added somewhere off the page.

Also, why does repaging after annotating not expand the canvas to show the hidden text?

Code: Select all

magick a.png -resize 100x -gravity east -splice 100x0 -fill black -pointsize 36 -annotate "+0+0" "test" +repage x:

Re: [Resolved]-annotate silently fails on some images

Posted: 2019-12-02T05:16:19-07:00
by snibgo
If your image is only 1x1 pixel, there isn't room to write much text. Any writing done outside the image boundaries has no effect. ImageMagick doesn't allocate any memory to record changes that occur outside an image.

Another point is that, sadly, the documentation doesn't say when the {geometry} part of an operation applies to the virtual canvas rather than the image. For example, https://www.imagemagick.org/script/comm ... s.php#crop says about crop:
Cut out one or more rectangular regions of the image.
... but it really cuts out from the virtual canvas.

Re: [Resolved]-annotate silently fails on some images

Posted: 2019-12-02T13:33:18-07:00
by user001
Interesting, I did not know that about crop. Hopefully the documentation will be updated to include this important detail.

Regarding the 1x1 pixel image, I did the following before adding text:

Code: Select all

magick a.png -resize 100x -gravity east -splice 100x0
So there should be space for the text.

Thanks for clearing up the fact that text written outside the canvas is effectively discarded; that explains why repaging after annotating outside the image has no effect.