I have a bunch of photos. They're all the same height, and I'm trying to put them together into a composite image using ImageMagick's montage program via Bash. The problem is that by default, the tile size (one image occupies one tile) is equal to the image with the largest dimensions. Narrow images, therefore, are surrounded by a lot of white space. I want to remove this white space. How can I do it?

Also, once you have differing sizes with montage, it gets a bit difficult to discern between what is "tile background" (tile space) vs "frame" and "border" - I lose track myself often, so here is a small test case with (clickable) images:

# "The 'tile' size is then set to the largest dimentions
# of all the resized images, and the size actually specified."
# "by removing the 'size' component, non of the images will
# be resized, and the 'tile' size will be set to the largest
# dimensions of all the images given"
# #02: specify -geometry offset (tile spacing)
# note: mont02.png is 1008x808 pixels now!
montage img1.png img3.png img2.png img4.png \
-geometry +2+2 \
mont02.png

EDIT: I put together a small Python/Tkinter/PIL GUI for ImageMagick, tkGui_ImageMagick.py - and finally I could find the proper command line for something that I wanted: to make a montage of four images, where the tiles' height & width are matched to whatever is the largest width of that column (or height of row).

In this example, img1 (200x100) and img2 (300x200) go in first column, the larger width is 300 - which should set the tile width of img1. Also, img1 needs to have it's height correlated to the larger height of img3 (300 px), with which it forms a row. This can be specified via the extent operator (see also ImageMagick • View topic - Resize and pad instead of stretch). And that command line requires subprocess calls to separate montages for each column - and from there, separate converts for each image:

... we will notice that the first specification for height (200) will be ignored, and 400 as larger will be applied to both tiles anyways!

Thus we must control the padding of each individual image (by calling convert with extents for each) - and then avoid extents in the montage line; and as such, we must apriori know the (largest) width of each column (and height of each row). Note also:

Since img1 is smaller than the implied width/height of its neighbors, we must explicitly set both width and height in its extents

The other dimension can have only the relevant dimension specified - and img4, as largest, doesn't have to be padded (and ran through convert) at all

In montage, usually -gravity has to come after (fully specified: w & h) -extent; in convert, -gravity works before-extent (usually)