imagemagickimagemagick-montage

How do I make the images equidistant using imagemagick/montage?


Currently I'm using this command:

montage IMG*.JPG -tile 3x1 -geometry 150x100+40+40 -background '#000000' triptych.jpg

And it produces an output like this (red lines added): too much space!

The problem (as indicated) is that my images have too much space between them, and that makes me sad.

I'm looking to create something that looks more like this, with the border equal all the way around:

equidistant excellence!

I checked the manpage and several online guides, but none of the options that I tried (-mode concatenate, changing the geometry to +40+20) did what I wanted.

How do I get the output that I want using imagemagick?


Solution

  • If you are just making a triptych, you may get on better with convert +append to lay out images in a row with spacers. So, if your images are 1.png, 2.png and 3.png:

    convert -background black \
      1.png xc:black[10x] 2.png xc:black[10x] 3.png +append \
      -bordercolor black -border 10 result.png
    

    enter image description here

    The xc:black[10] are just the two spacers that you can set the width of explicitly. Then the three images with spacers are set in a horizontal row, using +append. Finally, at the end, I put a border around the whole lot with -border.

    Or, showing how you have full control over all aspects:

    convert -background black \
      1.png xc:black[15x] 2.png xc:black[5x] 3.png +append \
     -bordercolor black -border 40 result.png
    

    enter image description here

    As Wayne says in the comments, you can resize all the images to a uniform size too, while they are still separate before the -append, so you can do this to make sure no image is wider than 400 pixels.

    convert -background black \
      1.png xc:black[10x] 2.png xc:black[10x] 3.png -resize 400x\> +append \
      -bordercolor black -border 10 result.png
    

    If you want even more control, you can individually resize the images like this:

    convert -background black               \
      \( 1.png -resize WxH \) xc:black[10x] \
      \( 2.png -resize AxB \) xc:black[10x] \
      \( 3.png -resize MxN \) +append       \
      -bordercolor black -border 10 result.png
    

    If you want a vertical triptych, use -append in place of +append and set the spacer height with xc:black[x10] rather than xc:black[10x].

    convert -background black \
      1.png xc:black[x10] 2.png xc:black[x10] 3.png -append \
      -bordercolor black -border 10 result.png
    

    enter image description here

    Keywords: triptych, diptych, montage, photographer, photography, photo, spacing, spacer, padding