Batch processing help. Is this possible?

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
RiGLEY
Posts: 3
Joined: 2011-07-10T07:55:36-07:00
Authentication code: 8675308

Batch processing help. Is this possible?

Post by RiGLEY »

Hi!

New user here. I'm writing a Windows script (AutoHotkey) for my university, which saves lots of .tif images into a directory. I have heard that Imagemagick is very good at batch image processing, so here goes my question: Lets say I have a reference file somewhere, and I want to add (or subtract) it to all of the pictures in the directory. And overwrite them. Any help would be much appreciated!

Thanks,
Daniel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch processing help. Is this possible?

Post by fmw42 »

RiGLEY wrote:Hi!

New user here. I'm writing a Windows script (AutoHotkey) for my university, which saves lots of .tif images into a directory. I have heard that Imagemagick is very good at batch image processing, so here goes my question: Lets say I have a reference file somewhere, and I want to add (or subtract) it to all of the pictures in the directory. And overwrite them. Any help would be much appreciated!

Thanks,
Daniel

IM has a multi-image processing functions called mogrify that processes every image (of the type specified) in a directory. Unfortunately, it does not allow a second image to be used in conjunction with all of the other images. Thus you will need to write a script. Or see http://www.imagemagick.org/Usage/basics/#mogrify_not

for mogrify, see http://www.imagemagick.org/Usage/basics/#mogrify
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Batch processing help. Is this possible?

Post by anthony »

Perhaps you need to describe or example what it is you are trying to achieve. What you have written could be interpreted in many many different ways.

It sounds like you want to take any image that appears in some directory and merge them into a existing larger image. But I can't be certain.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
RiGLEY
Posts: 3
Joined: 2011-07-10T07:55:36-07:00
Authentication code: 8675308

Re: Batch processing help. Is this possible?

Post by RiGLEY »

Hi!

Thanks for the replies. The reference image won't change. The ref image has the same dimensions. I want to give the script a line of code that takes the reference image and adds (for example the pixel values) it to all of the images in a directory. It can overwrite them.
__
Daniel
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Batch processing help. Is this possible?

Post by anthony »

Then mogrify is the solution.

However mogrify does not (currently) let you directly compose one image to multiple images (how does it know what is the reference image?). the solution is either...

Compose with Draw...
http://www.imagemagick.org/Usage/basics ... fy_compose
or use convert (read all images, process them all then write them all) -- very memory hungry
http://www.imagemagick.org/Usage/basics ... fy_convert
or a shell wrapper around convert -- runing multiple commands
http://www.imagemagick.org/Usage/basics/#mogrify_not

In IMv7 (currently being worked on) I will be creating a new alternative, a imagemagick co-process, whcih a shell script can feed image processing commands to. That is a background IM command (one only) that reads/processes/writes the images, according to commands given by a controlling shell script. This will have the same advantages as all the above, but few disadvantages.
http://www.imagemagick.org/Usage/bugs/I ... ipting.txt

However it may be some months before it is available.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Batch processing help. Is this possible?

Post by whugemann »

The command achieving this is:
for %i in (*.jpg) DO convert %i compare_to.jpg -compose subtract -composite mod_%i

Just open a DOS box, switch to the folder where the files are located and type the above command. When transferring the code into a batch file, you have to double the percent signs:

for %%i in (*.jpg) DO convert %%i compare_to.jpg -compose subtract -composite mod_%%i

and you can hand over the actual file to compare to:

for %%i in (*.jpg) DO convert %%i %1 -compose subtract -composite mod_%%i
DEL mod_%1

For details on batch processing with IM under Windows see the link below.
Wolfgang Hugemann
RiGLEY
Posts: 3
Joined: 2011-07-10T07:55:36-07:00
Authentication code: 8675308

Re: Batch processing help. Is this possible?

Post by RiGLEY »

I'm extremely grateful Wolfgang! Actually the other day I was browsing your page looking for some solution. :) Thanks guys!
Post Reply