Batch append on several photos with "paired" postfix 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
hauglien
Posts: 2
Joined: 2015-05-06T04:50:52-07:00
Authentication code: 6789

Batch append on several photos with "paired" postfix in Windows

Post by hauglien »

Hi.

I have a directory with two sets of images. The postfix of these files are matched in pairs, such as Top_0001.png,Top_0002.png,Bottom_0001.png,Bottom_0002.png. The output of these four files should be Combined_0001 and Combined_0002.
In reality, the postfix is random and there will be several thousand files to process.

ImageInput_Top
ImageInput_Bottom
ImageOutput

What would be the easiest way to append these images in a batch file? I have managed to google together something that works, but I do not quite understand WHY and HOW it works. Any comments are appreciated.

Code: Select all

@echo off
:: setLocal EnableDelayedExpansion
set targetdir="C:\temp"
set setnum=0

for /f "tokens=2 delims=_." %%a in ('dir /b /o-n %targetdir%\Top*.png') do convert %targetdir%\Top_%%a.png %targetdir%\Bottom_%%a.png -append %targetdir%\Combined_%%a.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch append on several photos with "paired" postfix in Windows

Post by snibgo »

The convert command takes two images, puts one above the other, and writes the output.

This is run inside a FOR loop, which run through all the names of the Top*.png files, extracting the 2nd token, where "_" is a separator. So %%a will take the values "0001", "0002" etc.

Does that answer the question?
snibgo's IM pages: im.snibgo.com
hauglien
Posts: 2
Joined: 2015-05-06T04:50:52-07:00
Authentication code: 6789

Re: Batch append on several photos with "paired" postfix in Windows

Post by hauglien »

Thanks, snibgo.

I was a bit unsure about the "token", but assumed it should be something like that. After I posted the message I also tried to program in some drag and drop functionality (based on this: http://www.imagemagick.org/Usage/windows/#filenames) . That did not work so well. I did not manage to combine the FOR loop with the example code. As I said, I am only able to Google together some code as the one above :-)
If someone has any tips regarding drag and drop with this code, I would really appreciate it.
Post Reply