Run imagemagick commands from a file in windows

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
jb2233
Posts: 6
Joined: 2017-09-24T19:28:03-07:00
Authentication code: 1151

Run imagemagick commands from a file in windows

Post by jb2233 »

Hi,

I currently create a batch file (.bat) that executes over 400 commands, ie magick is executed over 400 times.

Is it possible, and if so how, can I build a file that contains the commands and then have magick (in one execution) run the 400 commands.

This would be for performance reasons. I have "MAGICK_THREAD_LIMIT=1" set to stop multiple threads from running, there are dependencies in the commands.

Many thanks for your consideration any help will be greatly appreciated.

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

Re: Run imagemagick commands from a file in windows

Post by snibgo »

Yes, multiple invocations of magick can be combined into a single call to magick, which will take less time. In addition, if any invocations write results to disk that are only for reading by other invocations, these can be stored in memory within the single invocation, which reduces disk IO.

How? Just create one long magick command eg in a shell script, or put it in an IM script file that is called with "-script".

A couple of points:

1. A magick command has an implied "-write" before the final filename. As this will no longer be the final filename, you must make this explicit.

2. After each "-write filename", empty the image list, eg with "-delete 0--1".

3. If individual invocations change settings (eg "-compose CopyOpacity") but other invocations assume default values, you must explicitly set the values back to default (eg "-compose Over"). Sadly, there is no operation that changes all settings to defaults.

4. When combining multiple invocations into one, you should test that the outputs from the new code matches the output from the old code.
snibgo's IM pages: im.snibgo.com
jb2233
Posts: 6
Joined: 2017-09-24T19:28:03-07:00
Authentication code: 1151

Re: Run imagemagick commands from a file in windows

Post by jb2233 »

Many thanks for the quick response, I will try this out
Post Reply