Batch Pair Montage

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
Angstony
Posts: 2
Joined: 2017-05-17T09:42:22-07:00
Authentication code: 1151

Batch Pair Montage

Post by Angstony »

Hi,

I have a bunch of images the exact same size that I need to pair together with a 10px gap and a 5px border. They're all in the same folder and named appropriately: Left 0001.jpg, Right 0001.jpg, Left 0002.jpg, Right 0002.jpg, … etc.

After a lot of trial and error I've found that the 'montage' operation works perfectly as a single command, thus:

Code: Select all

montage -background black -geometry +5+5 "Left 0001.jpg" "Right 0001.jpg" "Frame 0001.jpg"
Now I don't want to have to go through re-running the command for every pairing, so I thought I'd try this:

Code: Select all

montage -background black -geometry +5+5 Left*.jpg Right*.jpg Frame*.jpg
But of course that just created a single huge image with all of the source images montaged.

So I guess I need to create a batch file (for Windows) and loop through with a wildcard, but I've never done any batch scripting before and I'm not sure where to even start with it. Any help would be greatly appreciated.
Angstony
Posts: 2
Joined: 2017-05-17T09:42:22-07:00
Authentication code: 1151

Re: Batch Pair Montage

Post by Angstony »

Okay, after doing some research on looping through files and a bit of trial and error I've managed to come up with this:

Code: Select all

@echo off
setlocal enabledelayedexpansion

for %%F in (Left*.jpg) do (
    set oldName=%%F
    set pairName=Right !oldName:~5!
    set newName=Frame !oldName:~5!
    echo Processing !newName!...
    magick montage -background black -geometry +5+5 "%%F" "!pairName!" "!newName!"
)
Hopefully someone will tell me if there's a simpler, safer, or more efficient way than this, but for now at least it's doing the job I wanted!
Post Reply