249

I would like to combine multiple images into one image using ImageMagick. To explain a little better, I want the result to look similar to this:

That is, I have a number of screenshots, and I want to turn them into one image with the original images on top of each other.

By Googling, I have come across the 'composite' command, but I don't know if, and in that case how to use it to get the result I want.

Vladimir Panteleev
  • 1,389
  • 1
  • 13
  • 20
Petter
  • 2,601
  • 3
  • 15
  • 6
  • Did you check out [imagemagick multi image layer examples](http://www.imagemagick.org/Usage/layers/)? – dertkw May 30 '11 at 19:35

2 Answers2

380

For any number of input files named in-<something>.jpg:

convert -append in-*.jpg out.jpg

In order to have specific files appended, or skip numbers instead of getting the full "glob", you can mention the input files explicitly and put the append command afterwards

convert in-1.jpg in-5.jpg in-N.jpg +append out-in1-plus-in5-and-inN.jpg

You can use -append (instead of +append) for vertical paste-up.

Or:

montage -mode concatenate -tile 1x in-*.jpg out.jpg

will also create a file out.jpg that contains a vertical concatenation of the source images.

convert

For simple concatenation in a single row or column, the append option of the convert tool is sufficient. Note that -append concatenates all images vertically, creating one column with n rows, and +append concatenates horizontally, creating one row with n columns.

(See ImageMagick: Command-line Options.)

montage

To get finer control over the layout, we would need the montage tool. montage -mode concatenate will glue the input images together like the append option and -tile 1x controls the layout to be applied.

tile follows the format columns×rows, but either side may be missing and montage will figure out how to meet the constraints.

We're using 1x (exactly one column with any number of rows) here to get the same effect as -append. Without -tile 1x, it would join the images like +append, defaulting to -tile x1 (any number of columns on one row).

(See ImageMagick Examples: Montage, Arrays of Images.)

peth
  • 9,890
  • 3
  • 34
  • 41
  • 3
    Thanks. append works fine, but I consider montage broken: if ghostscript fonts are not installed, it will bail out, EVEN if you are not annotating the images. Fonts should be loaded on demand, not in advance. – Bram Jan 05 '14 at 19:26
  • How would I skip every other image? I'd like to parse a subset - in-1, in-3, in-5, etc.. – Mike Robinson Jul 24 '14 at 17:57
  • 2
    @MikeRobinson ``convert -append `counter=0; for x in in-*; do if [[ $(($counter % 2)) == 0 ]]; then echo $x; fi; counter=$((counter + 1)); done` out.jpg`` should do the job. – gozzilli Nov 12 '14 at 15:59
  • 1
    @peth: Your answer starts with an example `convert` command that has `-append` ***before*** input file names.  An anonymous user added an example with `+append` ***after*** the input file names.  Are these both valid?  Is the order significant? – Scott - Слава Україні May 20 '16 at 02:50
  • 3
    Note that the `convert -tile 2x2` etc. command will read the files **alphabetically**. This means that chunks named `0-10` will be read like `0,10,1,2,..,9`. Took me almost 2 hours to realize something this basic. – phil294 Jul 23 '17 at 19:27
  • 1
    @Blauhirn: Is that convert sorting the filenames, or is that just your glob returning files in that order? e.g. `ls *` will return those values in that order. – naught101 May 08 '18 at 06:00
  • @naught101 Oh, you are right! I must have been using a glob there. – phil294 May 08 '18 at 10:46
  • I needed to add "magick" to the beginning of the command to make it work for me on Windows 11 from PowerShell. `magick convert -append *.jpg out.jpg` – blakemade Jul 29 '22 at 18:36
  • `convert` doesn't work for me. It generates multiple `out` files that are just plain copies of the originals – Eduardo Oct 11 '22 at 21:22
13

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

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: