Joel Dare

Stack Images with Image Magic

Sometimes I need to combine a handful of images together, stacking them vertically or horizontally.

Right now I’m writing some slot machine software and the wheels are a perfect example of this. Each symbol on each wheel is a 512x512 icon with a white background. I need to take a dozen of these and stack them into a strip of symbols.

I also need to do this with one or two images to show a series of screenshots. Particularly in cases where I can only attach a single image.

A nice command line tool for doing quick work with images is ImageMagick. I’m using ImageMagick 7.1.0-22 on Mac OS to write this article but it should work similarly for other versions and on other platforms.

In ImageMagick this “stacking” is called “appending” and it’s one of the easiest operations the software supports. Here’s the command to stack several images.

convert 1.jpg 2.jpg 3.jpg -append result.jpg

If you want to stack images horizontally you can switch the -append argument for +append in the example above.

See the ImageMagick documentation about the append option for more information.

Written by Joel Dare on February 5, 2022