56

This seems like it might be a reasonably common question, so I'm going to ask it using as many keywords as I can think of!

I have a bunch of (well, nine) tile jpegs, with standard tile filenames. Each jpeg is 220x175 pixels:

(top row)
tile_1_0_0.jpg
tile_1_1_0.jpg
tile_1_2_0.jpg
(middle row)
tile_1_0_1.jpg
tile_1_1_1.jpg
tile_1_2_1.jpg
(bottom row)
tile_1_0_2.jpg
tile_1_1_2.jpg
tile_1_2_2.jpg

How can I use imagemagick/montage to 'glue' or join them all together to make a single, coherent image? I don't want to resize them at all, so I guess the final image should be 660x525.

That would be montage with no framing, shadowing, bordering, etc - just the nine original images, glued together to make a single jpeg.

I know it should be something along these lines, but I'm struggling with getting the order and sizing right:

montage +frame +shadow +label -tile 3x3 -geometry <options> *.jpg joined.jpg
Jonathan
  • 6,741
  • 7
  • 52
  • 69
AP257
  • 89,519
  • 86
  • 202
  • 261
  • Also possibly related: [remove extra tilespace from a montage (ImageMagick) composite image? - Unix and Linux](http://unix.stackexchange.com/questions/4046/remove-extra-tilespace-from-a-montage-imagemagick-composite-image/63463#63463) – sdaau Feb 02 '13 at 16:36

3 Answers3

45

I was looking to do something similar and ended up here (I guess your "as many keywords as possible" thing worked). Here's what I came up with that worked for me. (geometry and tile adjusted for your needs)

montage -border 0 -geometry 660x -tile 3x3 tile* final.jpg

The files get added to the tiles horizontally, so, for -tile 4x2, the disposition would be:

1 2 3 4
5 6 7 8

The numbers being the relative positions of the filenames in the argument list.

As far as I can tell, tile* will expand alphabetically, so you should either specify your filenames manually, or rename then so that they'll sort appropriately, e.g.:

# top row
tile_r0_c0.jpg
tile_r0_c1.jpg
tile_r0_c2.jpg
# middle row
tile_r1_c0.jpg
tile_r1_c1.jpg
tile_r1_c2.jpg
# bottom row
tile_r2_c0.jpg
tile_r2_c1.jpg
tile_r2_c2.jpg
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
kch
  • 77,385
  • 46
  • 136
  • 148
  • I assumed `660x` was the final size (3 images @ 220px each). From reading [the example](http://www.imagemagick.org/Usage/montage/#geometry_size), I think the `-geometry` flag resizes *each* image to this size (thus, using `-geometry 220x` would maintain the original size in this case). Does that seem correct? – Hendy Jun 28 '17 at 04:57
  • `geometry` can either control a tiling border (`+w+h` option) and final size of the figure (`WxH`). However, the output will be resized if you don't add at least `+0+0` (see my full command below) – gluuke Dec 05 '18 at 14:16
38

Dave's solution didn't work for me, so I found a better answer here. Try this:

montage -mode concatenate -tile 3x3 tile*.jpg result.jpg

it also works without the second "3"

montage -mode concatenate -tile 3x tile*.jpg result.jpg

the complete line for Windows users is:

"C:\Program Files\ImageMagick-6.8.0-Q16\montage.exe" -mode concatenate -tile 3x tile*.jpg result.jpg

(change the "6.8.0-Q16" with your own version of ImageMagick, of course)

halfer
  • 19,824
  • 17
  • 99
  • 186
BearCode
  • 2,734
  • 6
  • 34
  • 37
4

I personally use this minimal command for such tasks:

montage tile*.jpg -tile 3x3 -geometry +0+0 output.jpg

geometry +0+0 will not add any border and conserve the original size of each image (a very much advised option).

gluuke
  • 1,179
  • 6
  • 15
  • 22