Page 1 of 1
IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T10:15:34-07:00
by GeeMack
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.
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T11:42:02-07:00
by fmw42
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.
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T13:00:06-07:00
by GeeMack
fmw42 wrote: ↑2018-01-22T11:42:02-07:00I 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.
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T13:14:22-07:00
by snibgo
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.
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T13:43:14-07:00
by fmw42
@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 ....
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T14:12:50-07:00
by GeeMack
snibgo wrote: ↑2018-01-22T13:14:22-07:00I 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.
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T14:46:40-07:00
by snibgo
"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
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T15:50:00-07:00
by snibgo
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
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T16:00:58-07:00
by fmw42
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).
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T16:58:00-07:00
by snibgo
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.
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T17:08:34-07:00
by fmw42
OK. Thanks for the clarification.
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T17:50:15-07:00
by GeeMack
snibgo wrote: ↑2018-01-22T16:58:00-07:00Except 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
Re: IM 6.9.9-33 - Windows 10 - odd error message
Posted: 2018-01-22T18:02:01-07:00
by snibgo
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