Page 1 of 1

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

Posted: 2015-05-06T05:32:21-07:00
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

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

Posted: 2015-05-06T11:04:29-07:00
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?

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

Posted: 2015-05-06T22:51:28-07:00
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.