Page 1 of 1
Problem with FX expression %[fx:n]
Posted: 2019-07-14T09:24:11-07:00
by GeeMack
Using IM 7.0.8-53 Q16 x64 HDRI on Windows 10. The FX expression "%[fx:n]" gives incorrect results when there are no images in the list. Here is an example command...
Code: Select all
magick logo: -duplicate 5 -delete 0--1 -print "%[fx:n]" null:
That should show the number of images in the list as "0", but instead incorrectly reports the number of images as "1".
The issue also occurs when using the "n" by itself inside square brackets as in this command...
Code: Select all
magick logo: -duplicate 5 -delete 0--1 -print "%[n]" null:
That reports "1" image, but it should show "0". Interestingly, without the square brackets it correctly reports "0" images, like this...
Code: Select all
magick logo: -duplicate 5 -delete 0--1 -print "%n" null:
The issue also occurs in version IM 6.9.10-11 Q16 x64 HDRI. I have no idea which version(s) were first to have this problem.
Re: Problem with FX expression %[fx:n]
Posted: 2019-07-14T12:38:30-07:00
by magick
ImageMagick is behaving properly. Querying properties requires an image container. In some cases, the user demands a property even if an image is not available so one is automagically created. For example, you might want to perform a FX calculation before an image is read:
Code: Select all
magick -print "%[fx:.8765/3.14]" null: null:
Rather than return an exception, an image is instead created to ensure the FX expression can be parsed and a value returned. The correct fix to this problem, is to update the documentation so users are aware of this behavior.
Re: Problem with FX expression %[fx:n]
Posted: 2019-07-14T13:29:19-07:00
by GeeMack
magick wrote: ↑2019-07-14T12:38:30-07:00
ImageMagick is behaving properly. Querying properties requires an image. In some cases, the user demands a property even if an image is not available so one is automagically created. For example, you might want to perform a FX calculation before an image is read, for example,
Code: Select all
magick -print "%[fx:.8765/3.14]" null: null:
Thanks for the explanation. I should have known that.
I'm working on commands using FX expressions to "-set option:variable" to the number of images currently in the list. Then I'll use that variable later in the command for duplicating or deleting. I can get what I need by creating a placeholder "xc:", setting the variable to the length of the list minus 1, then deleting that placeholder, something like this...
Code: Select all
... xc: -set option:list_length %[fx:n-1] +delete ...
Thanks again!