Page 1 of 1

Problem with while() inside -format

Posted: 2019-04-29T01:05:14-07:00
by SafetyCar
Hi, I'm having a problem using while() inside -format. I'm using ImageMagick through COM so the code is a little weird to paste exactly so, summarizing...

Something like this works:

Code: Select all

convert FILEPATH -format %[fx:abc=3;while(abc<3){abc=abc+1;};abc] info:
But this makes the program freeze:

Code: Select all

convert FILEPATH -format %[fx:abc=3;while(abc<4){abc=abc+1;};abc] info:
It's like the variable is not incremented. I was thinking of posting as a bug but wanted to check first.

Re: Problem with while() inside -format

Posted: 2019-04-29T05:23:32-07:00
by magick
Refer to the FX docs. The correct syntax is while(condition,expression):

Code: Select all

convert wizard: -format '%[fx:abc=3;while(abc<4,abc=abc+1);abc]' info:

Re: Problem with while() inside -format

Posted: 2019-04-29T05:38:14-07:00
by SafetyCar
Whoops... thanks, I don't know how I missed that.

Re: Problem with while() inside -format

Posted: 2019-04-29T05:58:37-07:00
by SafetyCar
@magick Sorry again but I'm trying more things...

And this code is always executed at least once (outputting 15):

Code: Select all

-format %[fx:abc=5;while(abc<0,abc=abc+10);abc]

Re: Problem with while() inside -format

Posted: 2019-04-29T07:10:20-07:00
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 @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.

Re: Problem with while() inside -format

Posted: 2019-05-01T11:35:07-07:00
by SafetyCar
Seems to be working as expected now.