Need help batch combining/overlaying different folders of images
Need help batch combining/overlaying different folders of images
I have a slightly different problem, I would like to append the first image in Folder A with the first image in Folder B. Append the 2nd image in Folder A with the 2nd image in Folder B and repeat the process for all files. Both folders have the same number of images and are of the same size and resolution. I would like the output to be saved in Folder C. I have over 1000 images and I would like the output to serially numbered, starting with "merged0001.png" and saved in Folder C. I use ubuntu 14.04. any help with the script will be very helpful. Thanks.
Re: Need help batch combining/overlaying different folders of images
something like this, assuming your images are all *.png
replace A, B, C to the actual paths of your folders A, B, C
Test it before using it (use echo, e.g.,
replace A, B, C to the actual paths of your folders A, B, C
Test it before using it (use echo, e.g.,
Code: Select all
echo "convert $f $g -append $C/$(printf "merged%04d.png" $i)
Code: Select all
#!/bin/sh
A=/path/to/folderA
B=/path/to/folderB
C=/path/to/folderC
ls $B/*.png > listB.txt
i=0
for f in $A/*.png
do
i=$((i+1))
g=$(head -n$i listB.txt | tail -n1)
convert $f $g -append $C/$(printf "merged%04d.png" $i)
done
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Need help batch combining/overlaying different folders of images
I'm using ImageMagick 6.9.3-9 on Windows 7 64, so I haven't tested it on *nix shell, but something like this should get you going in the right direction...srinivasv wrote:I have a slightly different problem, I would like to append the first image in Folder A with the first image in Folder B. Append the 2nd image in Folder A with the 2nd image in Folder B and repeat the process for all files. Both folders have the same number of images and are of the same size and resolution. I would like the output to be saved in Folder C.
Code: Select all
convert \
FolderA/*.png \
-gravity north \
-extent 100%x200% \
null: \
FolderB/*.png \
-gravity south \
-layers composite \
-scene 1 \
FolderC/merged%04d.png
It sets the gravity to "north" and increases the canvas size of those FolderA images to 200% of the height by adding more canvas to the bottom of each.
Then it calls in the "null:" image to separate the stack you just created from the next stack coming up. <-- Very important.
Then it will bring in all the PNG images from FolderB.
Next it sets the gravity to "south" so the composite operation places the FolderB images on the lower half of the now extended FolderA images.
The "-layers composite" operation alternately takes the images from FolderA and FolderB stacks, compositing each FolderB image onto the bottom half of its companion FolderA image. That's what the "null:" between the two stacks of images does.
It finishes by putting all the output images in FolderC, numbered to 4 places, starting at 1 with "-scene 1", and with filenames like "merged0001.png", "merged0002.png", ... "merged9999.png".
You may have to swap the gravity north/south if you want the FolderB image on top.
You can even change it to east/west if you want them appended side by side instead of over/under. You'll need to change the extent operation to "-extent 200%x100%" to double the width instead of height of the canvas if you make them go side by side.
Re: Need help batch combining/overlaying different folders of images
Thanks. Tested it on a small set. Worked perfectly!
[quote="vonbiber"]something like this, assuming your images are all *.png
replace A, B, C to the actual paths of your folders A, B, C
[quote="vonbiber"]something like this, assuming your images are all *.png
replace A, B, C to the actual paths of your folders A, B, C