April 29, 2020

Tiling Images With Imagemagick

While writing this post about installing KVM and virt-manager, I wanted to show multiple steps of a process by capturing the window for each screen.

Getting the images was quite simple, but including them one by one in a blog post seemed a bit tedious, even though there were only 5 images. Especially given that including images in markdown seems… impossible !

I knew about imagemagick before, but had never really used it, or went to see into the documentation. After a little research, I found the montage command, which allows you to create a composite image by combining several separate images.

Creating a montage for my post

I went on to create the following image, using the 5 images that I captured before

Tiled images

Here is the command that I used to create this image from 5 others

magick montage -tile 2x3 -geometry +5+5 -shadow \
    Image_1.png Image_2.png Image_3.png Image_4.png Image_5.png \
    New_Image.png

This command is really straightforward. First, tell imagemagick to do a montage, using a -tile layout of 2x3.

The -geometry option here allows me two things. First, without giving it anything before the first +, it tells it to use the size of the original images. The +5+5 then adds inside borders of 5 pixels on the x and y axes, creating gaps between each picture. If you want more information about this option, you can go and look directly in the documentation for exactly what you need. (Don’t hesitate to leave a comment with a question if necessary !)

For fun, I added the -shadown option which creates a small, configurable shadown under each image. The default configuration was perfect for me.

Then come the names of the original images, in the order I wanted them to be displayed, from top left to bottom right.

Finally, the name of the generated image. Don’t forget this one, or you may have to recapture the last of your images (I speak from experience).

It is really not hard, but it may take a bit of trial and error to get exactly what you want. Don’t hesitate to try multiple times.

Imagemagick is an old and powerful wizard

This tool is very powerful. So much so that while it may be fun to go and look around in the documentation, I would not recommend learning it without a goal. Use it if you have a specific need, like I had.

It is very useful for scripting and repeatability, which is why it was perfect for this montage. I did not have to open any big image editor, worry about aligning pixels, and I even got shadows for free !!!

But it can do so much more than just put images together. It will do anything you can think of with an image and more. Need to process terabyte-size images ? Not a problem. Edge detection ? Done. A simple light adjustment ? Of course !

Respect this ancestor, and it can become your best ally. But being so big, it will also probably beat you down for a while in the process.

Good luck !

Copyright Marin Gilles 2019-2022