Merge Images Side by Side (Horizontally)


Imagemagick Problem Overview

I have five images of sizes: 600x30, 600x30, 600x30, 600x30, 810x30. Their names are: 0.png, 1.png, 2.png, 3.png, 4.png, respectively.

How do I merge them Horizontally to make an image of size 3210x30 with ImageMagick?

Imagemagick Solutions

Solution 1 - Imagemagick

ImageMagick ships with the montage utility. Montage will append each image side-by-side allowing you to adjust spacing between each image (-geometry), and the general layout (-tile).

montage [0-4].png -tile 5x1 -geometry +0+0 out.png

Other examples can be found on Montage Usage page

Solution 2 - Imagemagick

ImageMagick has command line tool named 'convert' to merge images horizontally, or for other purpose. i have tried this command and working perfectly on your case:
To join images horizontally:
convert +append *.png out.png

To stack images vertically:
convert -append *.png out.png

Solution 3 - Imagemagick

Use -resize if the images don't have the same width/height

You can fix the height for all of them with the -resize option, e.g. to fix a 500 pixel height on two images joined horizontally:

convert +append image_1.png image_2.png -resize x500 new_image_conbined.png

Or for vertical joins, you would want to set a fixed width instead:

convert -append image_1.png image_2.png -resize 500x new_image_conbined.png


image_1.png 1067x600

enter image description here

image_2.png 1920x1080

enter image description here

new_image_conbined.png 889x500

enter image description here


How to do it interactively with GIMP

If you need to crop/resize images interactively first, which is often the case, then GIMP is the perfect tool for it, here's a detailed step-by-step:

enter image description here


ImageMagick 6.9.11-60 doesn't handle them, so see:

Solution 4 - Imagemagick

Very simple with ImageMagick (brew install imagemagick )

convert +append image_1.png image_2.png new_image_conbined.png

Solution 5 - Imagemagick

Anyone using the MiniMagick rails gem can use the built-in tool to merge images:

# Replace this with the path to the images you want to combine
images = [

processed_image = do |image|
  image.geometry "x700+0+0"
  image.tile "#{images.size}x1"
  images.each {|i| image << i}
  image << "output.jpg"

Check out the documentation for #geometry options to handle resizing and placement. The current example will resize images to a 700px height while maintaining the image's aspect ratio. +0+0 will place the image with no gaps between them.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSasuke KunView Question on Stackoverflow
Solution 1 - ImagemagickemcconvilleView Answer on Stackoverflow
Solution 2 - ImagemagicktesmojonesView Answer on Stackoverflow
Solution 3 - ImagemagickCiro Santilli Путлер Капут 六四事View Answer on Stackoverflow
Solution 4 - ImagemagickThiagoView Answer on Stackoverflow
Solution 5 - ImagemagickMyk KlemmeView Answer on Stackoverflow