Problem with while() inside -format

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
SafetyCar
Posts: 6
Joined: 2014-06-04T10:12:16-07:00
Authentication code: 6789

Problem with while() inside -format

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Problem with while() inside -format

Post 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:
SafetyCar
Posts: 6
Joined: 2014-06-04T10:12:16-07:00
Authentication code: 6789

Re: Problem with while() inside -format

Post by SafetyCar »

Whoops... thanks, I don't know how I missed that.
SafetyCar
Posts: 6
Joined: 2014-06-04T10:12:16-07:00
Authentication code: 6789

Re: Problem with while() inside -format

Post 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]
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Problem with while() inside -format

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 @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.
SafetyCar
Posts: 6
Joined: 2014-06-04T10:12:16-07:00
Authentication code: 6789

Re: Problem with while() inside -format

Post by SafetyCar »

Seems to be working as expected now.
Post Reply