Ubuntu – Stitching a photo below a batch of photos

photophoto-management

I am sure there would be a simple command for this however I have not been able to find one.

Basically I would like to stitch a photo below another photo with no overlap. Also ideally I would like a command that can automate this process for 200 top images where the same bottom image is stitched. All images have the same width so no transformation is required.

I am looking for a program something like "stitch -below top.png bottom.png", I have explored options like Montage but can not seem to get it to work as required. Looking for advise.

Best Answer

First you need to open a terminal and sudo apt-get install imagemagick.

Now place all your images in the same folder so you can easily access them from the terminal. Put the top images all in their own folder and keep the bottom image elsewhere to simplify things.

Type cd DIRNAME, you need to replace DIRNAME with the name of the folder the pictures are stored in, for example /home/mark/collating is what I use for this purpose.

Now that your shell is in the right folder and imagemagick is installed we use the following to stick the images together:

convert -append image1.jpg image2.jpg output.jpg

This will take the two images named image1 and image2 and stick image2 on the bottom of image1, saving the result as a file named output.jpg.

To automate this you can use a script like this one. You need to change the variables so they point to the right places.

#! /bin/bash

#   Replace the values of these variables with the locations of your tops and the bottom.
# The output directory must already exist!
#   "~/" is a shortcut for your home dir, FYI.

TopsDir="~/collating/tops" #Only the TOP images should be in this folder!
BottomImg="~/collating/bottom.png"
OutputDir="~/collating/complete"

[ -d "$TopsDir" -a -d "$OutputDir" ] && [ -f "$BottomImg" ] || { echo "One of the paths you supplied wasn't valid."; exit 1;}

cd "$TopsDir"

for TopImg in *; do
    convert -append "$TopImg" "$BottomImg" "$OutputDir/$TopImg"
done

Copy and paste it into gedit or your text editor and edit the variables so that they point to the correct folders. (Or file for the bottom img.) Save it as collator.sh. It is convenient for the next steps if you save it in your home directory.

Now open a terminal and navigate to where you saved the file. (You're already there if you saved it in your home dir, otherwise type cd /path/to/your/location) Type chmod +x collator.sh to give the file execute permissions.

And now we get the work done:
Type ./collator.sh to run the script; and you're done.

Related Question