Merge Images Side by Side (Horizontally)

Viewed 67830

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?

6 Answers

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

Example:

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

Related:

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: https://graphicdesign.stackexchange.com/questions/83446/gimp-how-to-combine-two-images-side-by-side/145543#145543

enter image description here

SVGs

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

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 = [
  "image1.jpg",
  "image2.jpg"
]

processed_image = MiniMagick::Tool::Montage.new do |image|
  image.geometry "x700+0+0"
  image.tile "#{images.size}x1"
  images.each {|i| image << i}
  image << "output.jpg"
end

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.

The convert +append method described in other answers appends images horizontally, aligned to the top. If you prefer to align to the bottom or center, try:

convert input1.png input2.png -gravity South +append output.png
  or
convert input1.png input2.png -gravity Center +append output.png

Source: Fred's ImageMagick Tidbits http://www.fmwconcepts.com/imagemagick/tidbits/image.php#append

Related