How to Stack Images Vertically with ImageMagick?

This article provides a quick overview and practical guide on how to combine multiple images into a single vertical stack using the ImageMagick command-line tool. You will learn the exact syntax for the convert (or magick) command, understand how to manage different image widths, and see examples of how to add spacing or padding between your stacked images.

The Basic Vertical Stacking Syntax

To stack images vertically, ImageMagick uses the -append option. This option takes all the images currently loaded into the command and glues them together from top to bottom in the order they are listed.

convert image1.jpg image2.jpg image3.jpg -append output_vertical.jpg

If you are using ImageMagick v7 or newer, the convert command has been replaced by the primary magick binary, though the syntax remains the same:

magick image1.jpg image2.jpg image3.jpg -append output_vertical.jpg

Handling Images of Different Widths

When you stack images that do not have the same width, ImageMagick’s default behavior is to align them to the left. The total width of the final output image will match the width of the widest input image. The narrower images will have empty canvas space filled in on their right side.

To control how narrower images are positioned within the stack, you can use the -gravity setting before appending them.

Centering the Images

convert image1.jpg image2.jpg -gravity Center -append output_centered.jpg

Aligning Images to the Right

convert image1.jpg image2.jpg -gravity East -append output_right.jpg

Adding Space Between Stacked Images

If you do not want the images to touch directly, you can introduce a background color and expand the canvas of each image using the -border or -splice options before appending them.

An easy way to add a uniform gap between every image is to add a bottom border to the images before they are joined together:

convert image1.jpg image2.jpg -background white -splice 0x10 -append output_with_gaps.jpg

In this command, -splice 0x10 adds a 10-pixel vertical gap above the images, using the color specified by the -background flag to fill the newly created space.