Imagemagick – Tips and Tricks No. 2


The ability to combine a set of images into one image in a variety of ways, essentially replicates the contact sheets of old. Here are a few ways to create a montage. It works best when all the images are the same height and width. IM does not understand page sizes, and will just create a simple image, regardless of the number of images, you can tell IM which images to use though. It also makes sense when testing and creating montages to save the output to a different directory, otherwise your montages will be included in the next iteration!

One word of warning along the way, some images will carry with them metadata, which may make creating montages “without” labels a frustrating exercise. I found this to be an issue with png files. You can remove all the metadata using a program called exiftools. Install this on your linux system as follows:

sudo apt-get install libimage-exiftool-perl

To view information held in a file run:

exiftool mg.jpg

If you have a directory full of png image files, you can remove the information from all the files with this command:

exiftool -all= -overwrite_original -ext png .

OK, on to some examples of montage creation:

1. Simple montage of a set of images:

montage *.jpg ~/IMtest/mymontage.jpg
(you can use file names if you wish)


2. Simple montage in one row

montage *.jpg -tile x1 ~/IMtest/mymontage2.jpg


3. Simple montage in one column

montage *.jpg -tile 1 ~/IMtest/mymontage3.jpg


4. Simple montage in 2 columns and 3 rows

montage *.jpg -tile 2x3 ~/IMtest/mymontage4.jpg


As you can see IM is automagically adding a white border. This can all be modified (reminding ourselves of exiftools).

5. Simple montage with no borders (my images have a black border of 0.5 pixels)

montage *.jpg -geometry +0+0 ~/IMtest/mymontage5.jpg


6. Simple montage with a blue border of 4 pixels (note that you get 4 pixels on the outside border but 8 pixels on the inner!). You can use any colour you like for borders, use hex notation.

montage *.jpg -border 4x4 -bordercolor blue -geometry +0+0 ~/IMtest/mymontage6.jpg


To get the same width for the outside border, you need to pipe the first command to a second (note the order of bordercolor and border in the convert pipe, it is important!):

montage *.jpg -border 4x4 -bordercolor blue -geometry +0+0 jpg:- | convert - -bordercolor blue -border 4x4 ~/IMtest/mymontage7.jpg


7. Simple montage with sized images (because I am using block colours I’ll use a different height and width for demonstration purposes)

montage *.jpg -geometry 50x75\!+0+0 ~/IMtest/mymontage8.jpg

(note the escaped exclamation mark – “\!”, this overcomes the aspect ratio)


9. Simple Montage with filenames as labels

montage -label '%f' *.jpg -geometry +4+4 ~/IMtest/mymontage10.jpg


One thought on “Imagemagick – Tips and Tricks No. 2

  1. Pingback: Imagemagick – Tips and Tricks No. 3 | METRIC RAT

Leave a Reply

Your email address will not be published. Required fields are marked *