How to Append Two Images Horizontally with ImageMagick?

This article provides a quick overview and a step-by-step guide on how to use the ImageMagick convert command (or the magick command in newer versions) to merge two images side-by-side horizontally. You will learn the exact syntax required for basic horizontal appending, how to handle images of different heights, and how to add spacing or borders between the combined images.

The Basic Horizontal Append Command

To join two images horizontally, ImageMagick uses the +append option. This option takes the images currently in the stack and glues them together from left to right.

Here is the fundamental command structure:

convert image1.jpg image2.jpg +append output.jpg

If you are using ImageMagick v7 or later, the convert tool is integrated into the main magick binary, though the logic remains identical:

magick image1.jpg image2.jpg +append output.jpg

Handling Different Image Heights

When you append images horizontally that do not share the same vertical dimensions, ImageMagick defaults to aligning them by their top edges. This can leave blank space under the shorter image.

To control how the images align vertically, you can use the -gravity setting before the +append flag.

For example, to center two images vertically while joining them horizontally, use:

convert image1.jpg image2.jpg -gravity Center +append output.jpg

Adding Space Between the Images

If you do not want the images to touch directly, you can introduce a gap or a border between them. The cleanest way to do this without altering the original files is by using the -background and -splice settings to add extra pixels to the side of the first image before appending.

convert image1.jpg -background white -splice 10x0 image2.jpg +append output.jpg

In this command, -splice 10x0 adds a 10-pixel wide transparent or background-colored strip to the right side of image1.jpg before image2.jpg is attached next to it.