IM 6.9.9-33 - Windows 10 - odd error message

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

IM 6.9.9-33 - Windows 10 - odd error message

Post by GeeMack » 2018-01-22T10:15:34-07:00

Using ImageMagick 6.9.9-33 HDRI on Windows 10, I've come across an odd output to a particular command. I've reduced the command to just what it takes to create the issue. From the command line I try this...

Code: Select all

convert rose: -duplicate 3 -set page "+%[fx:w/(n-1)]+0" ( +clone -write tmp.png +delete ) output.gif
The result is a successful GIF with four frames and proper paging specs, but it issues this error message...

Code: Select all

convert.exe: divide by zero `w/(n-1.0*1)' @ error/fx.c/FxEvaluateSubexpression/2178.
Obviously that part of the error "w/(n-1.0*1)" is quite different from the actual FX expression in the command. To add to the mystery, if I "-write tmp.png" that intermediate file as another format like "tmp.gif", "tmp.jpg", or "tmp.tif", the command doesn't generate an error. It only seems to occur when I write that file as a PNG.

User avatar
fmw42
Posts: 23627
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by fmw42 » 2018-01-22T11:42:02-07:00

I do not think you can do that in IM 6. It works fine in IM 7 and fails for me in IM 6. I do not think -set page knows about %n in IM 6. If you substitute 4 in for n, then it works in IM 6. That confirms it to me.

User avatar
GeeMack
Posts: 608
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by GeeMack » 2018-01-22T13:00:06-07:00

fmw42 wrote:
2018-01-22T11:42:02-07:00
I do not think you can do that in IM 6. It works fine in IM 7 and fails for me in IM 6. I do not think -set page knows about %n in IM 6. If you substitute 4 in for n, then it works in IM 6. That confirms it to me.
The command produces the expected result other than the error message. It doesn't squawk if I use any of these FX expressions...

Code: Select all

... %[fx:w/n] ...

... %[fx:w/(n+1)] ...

... %[fx:w/(n-2)] ...
It also doesn't send an error message if I write that "tmp.png" inside the parentheses as a GIF, JPG, TIF, etc.

snibgo
Posts: 10514
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by snibgo » 2018-01-22T13:14:22-07:00

I don't understand the mystery. Within the parentheses, the number of images is one. So n=1, and n-1=0, so there is a divide by zero. This is evaluated only if needed, such as when the output is a PNG.

The error message is a bit weird, I assume because IM has tokenised the expression, and is de-tokenising it for the message. But that evaluates to the same, n-1*1, so it is still zero.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 23627
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by fmw42 » 2018-01-22T13:43:14-07:00

@snibgo.

n is the number of images in the sequence. He has the input plus -duplicate 3, so 4 images in the sequence.

convert rose: -duplicate 3 ....

User avatar
GeeMack
Posts: 608
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by GeeMack » 2018-01-22T14:12:50-07:00

snibgo wrote:
2018-01-22T13:14:22-07:00
I don't understand the mystery. Within the parentheses, the number of images is one. So n=1, and n-1=0, so there is a divide by zero. This is evaluated only if needed, such as when the output is a PNG.

The error message is a bit weird, I assume because IM has tokenised the expression, and is de-tokenising it for the message. But that evaluates to the same, n-1*1, so it is still zero.
I would think resetting the paging information inside the parentheses with "+repage", "+set page", or "-set page +0+0" might prevent that, but apparently the calculation sticks with that clone all the way up to, but not including, the output.

Code: Select all

convert rose: -duplicate 3 -set page "+%[fx:w/(n-1)]+0" ( +clone +repage -write tmp.png +delete ) output.gif

convert.exe: divide by zero `w/(n-1.0*1)' @ error/fx.c/FxEvaluateSubexpression/2178.

snibgo
Posts: 10514
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by snibgo » 2018-01-22T14:46:40-07:00

"n" is the number of images in the current sequence. Inside the parenthesis, the value of n is 1. For example:

Code: Select all

f:\web\im>%IM%convert rose: -duplicate 3 ( +clone -format "N=%n\n" -write info:
+delete ) info:
N=1  <== this is the output from within the parenthesis.
N=4
N=4
N=4
N=4
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 10514
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by snibgo » 2018-01-22T15:50:00-07:00

GeeMack wrote:I would think resetting the paging information inside the parentheses with "+repage", "+set page", or "-set page +0+0" might prevent that, but apparently the calculation sticks with that clone all the way up to, but not including, the output.
The string expression isn't expanded until it is needed. This is more clearly seen with "-format", and I assume "-set page" works in the same way, so it substitutes values as appropriate to each image. For example:

Code: Select all

f:\web\im>%IM%convert rose: -duplicate 3 ( +clone -resize 200% -format "W=%w; N=%n\n" -write info: +delete ) info:

W=140; N=1
W=70; N=4
W=70; N=4
W=70; N=4
W=70; N=4
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 23627
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by fmw42 » 2018-01-22T16:00:58-07:00

In GeeMack's first command

convert rose: -duplicate 3 -set page "+%[fx:w/(n-1)]+0"

The computation is before the parenthesis. So n should be 4 ( or perhaps 4444).

snibgo
Posts: 10514
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by snibgo » 2018-01-22T16:58:00-07:00

Except that the computation isn't done then. The page is merely set to a string, and the string isn't expanded until it is needed.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 23627
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by fmw42 » 2018-01-22T17:08:34-07:00

OK. Thanks for the clarification.

User avatar
GeeMack
Posts: 608
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by GeeMack » 2018-01-22T17:50:15-07:00

snibgo wrote:
2018-01-22T16:58:00-07:00
Except that the computation isn't done then. The page is merely set to a string, and the string isn't expanded until it is needed.
It seems the need for the calculation might be eliminated by resetting the paging for that one image inside the parentheses using one of these methods, but they all generate the same error message.

Code: Select all

convert rose: -duplicate 3 -set page "+%[fx:w/(n-1)]+0" ( +clone -set page +0+0 -write tmp.png +delete ) output.gif

convert rose: -duplicate 3 -set page "+%[fx:w/(n-1)]+0" ( +clone -set page "+%[fx:w/2]+0" -write tmp.png +delete ) output.gif

convert rose: -duplicate 3 -set page "+%[fx:w/(n-1)]+0" ( +clone +repage -write tmp.png +delete ) output.gif

convert rose: -duplicate 3 -set page "+%[fx:w/(n-1)]+0" ( +clone +set page -write tmp.png +delete ) output.gif

snibgo
Posts: 10514
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM 6.9.9-33 - Windows 10 - odd error message

Post by snibgo » 2018-01-22T18:02:01-07:00

I don't know why setting the page inside the parentheses doesn't cure the problem. I guess the previous page setting isn't removed, and gets expanded, even though it isn't used.

Moving the "-set page" to after the parentheses does cure the problem:

Code: Select all

convert rose: -duplicate 3 ( +clone -set page "+%[fx:w/2]+0" -write tmp.png +delete ) -set page "+%[fx:w/(n-1)]+0" output.gif
snibgo's IM pages: im.snibgo.com

Post Reply