Problem using negative index numbers in stack?

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: 735
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Problem using negative index numbers in stack?

Post by GeeMack »

Using IM 7.0.3-9 on Windows 10 64. I've run into a discrepancy when trying to access specs from one particular image in a stack if I use a negative number as an index. This command creates ten square white canvases sized 100x100, 101x101 ... 109x109, and outputs the specs to "info:"...

Code: Select all

magick xc:white -duplicate 9 -resize %[fx:100+t] info:
If I want to get the size of the first image in the stack I can do something like this...

Code: Select all

magick xc:white -duplicate 9 -resize %[fx:100+t] -format "%[fx:s[0].w]x%[fx:s[0].h] " info:
That shows the dimensions of index 0, the first image in the stack, as 100x100, which is what I would expect. Then if I want to get the dimensions of the last image in the stack, the one with index number 9, I can run this command...

Code: Select all

magick xc:white -duplicate 9 -resize %[fx:100+t] -format "%[fx:s[9].w]x%[fx:s[9].h] " info:
That shows the dimensions are 109x109, again what I'd expect. The problem comes if I have a stack with an unknown number of images, and I use index -1 to access the dimensions of that last image. Running a command like this...

Code: Select all

magick xc:white -duplicate 9 -resize %[fx:100+t] -format "%[fx:s[-1].w]x%[fx:s[-1].h] " info:
... shows the dimensions as 100x100 where I would expect it to show 109x109. Not only would I expect that -1 index to give me the dimensions of the last image, this command using the -2 index...

Code: Select all

magick xc:white -duplicate 9 -resize %[fx:100+t] -format "%[fx:s[-2].w]x%[fx:s[-2].h] " info:
... shows the 109x109 dimensions.

So using a zero or a positive number will find the image at the correct location in the stack, but it looks like the result from using a negative number as an index is off by one from where I think it should be.

User avatar
magick
Site Admin
Posts: 11133
Joined: 2003-05-31T11:32:55-07:00

Re: Problem using negative index numbers in stack?

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