skip to Main Content

I have a folder containing 4 sub-folders, and each sub-folder contains 4 images (for a total of 16 images). I want to combine these 16 images into 1 image.

Example of structure:

0/0.png
0/1.png
...
1/0.png
1/1.png
...
3/3.png

This is how the images are combined into one image:

Each column represents a sub-folder.

I have +30 of these folders, and that’s why I want to create a script instead of doing it manually in Photoshop.

I downloaded ImageMagick for Windows and tried to create a batch script that I could run.

I tried this:

cd %cd%
for /r /d %%a in (*.png) do montage -tile 5x4 "result.png"

This doesn’t work (no image, nor error in CMD). Please note that I am completely new to both ImageMagick and creating .bat files in Windows.

So, how can modify my script so it goes through all the sub-folders and creates/convert a single montage/tile from all the images in the sub-folders?

2

Answers


  1. Your example loops through all images, but you are doing it in the current dir only, not sub directories. The command also does not even use the metavariable %%a anywhere and if it did, it performs the do function to each file seperately.

    You could just loop through the images using dir, get each and append them using set /p in batch. so no matter how many images you have, it should loop through them.. Here I just store the result in a tmp file to use it in another loop, but there are many ways.

    @echo off
    set "myt=%temp%out.tmp"
    for /f %%i in ('dir /b /a-d /S *.png') do echo| set /p = ("%%~fi" -append)>>"%myt%"
    for /f "delims=" %%b in (%myt%) do magick.exe %%b +append result.png
    del /Q "%myt%">nul
    

    NOTE I am not too farmiliar with magick so not sure if the double quotes will cause issues, however I doubt it as paths with spaces would should cause issues.

    Login or Signup to reply.
  2. I do not know Windows scripting syntax. But if you loop over each directory of your 30 directories and run the following ImageMagick command from Mark Setchell converted to Windows slashes, that should work.

    magick.exe ( 0*.png -append ) ( 1*.png -append ) ( 2*.png -append ) ( 3*.png -append ) +append result.png
    

    Since I do not know Windows .bat scripting, it is possible that the answer from Gerhard Barnard may do just that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search