Home / Alt manpages / montage-im6.q16(1)

  • montage-im6.q16(1)
  • User command
  • linux

Build a labelled image contact sheet with ImageMagick montage

You will turn a directory of images into one labelled contact sheet, with a predictable grid, consistent thumbnail sizing and a separate output file. The examples use the installed ImageMagick 6 command, montage-im6.q16, also available here as montage and montage-im6. Allow about fifteen minutes if your images are already in one directory.

You need readable input images, a writable output directory and the imagemagick-6.q16 package. The installed version on this machine is ImageMagick 6.9.12-98 Q16, from package version 8:6.9.12.98+dfsg1-5.2ubuntu0.1~esm14. This guide describes that installed ImageMagick 6 behaviour. It does not require elevated privileges: do not use sudo for ordinary image work.

1. Check the command before choosing files

Confirm which executable your shell will run, then read its version. These are read-only checks:

$ command -v montage
/usr/bin/montage
$ montage --version
Version: ImageMagick 6.9.12-98 Q16 x86_64
$ dpkg-query -W -f='${Package} ${Version}\n' imagemagick-6.q16
imagemagick-6.q16 8:6.9.12.98+dfsg1-5.2ubuntu0.1~esm14

The command shape is montage input-files options output-file. The output must be the final file argument. The filename suffix, such as .png or .jpg, selects the output format unless you use an explicit ImageMagick format prefix.

Checkpoint

If command -v finds nothing, stop and install ImageMagick through your normal package-management process. A missing command is not a reason to run an unfamiliar downloaded binary.

2. List the inputs without changing anything

First inspect the files that your shell pattern will expand. Use a pattern that matches only the images intended for this sheet:

$ printf '%s\n' /path/to/photos/*.jpg
/path/to/photos/blue.jpg
/path/to/photos/red.jpg

If the pattern does not match, many shells leave the literal pattern unchanged. Check the directory and file extensions rather than creating a montage from an accidental filename. A filename containing whitespace is handled safely when the shell expands a pathname, but avoid putting an untrusted pattern into a script without testing it first.

For a repeatable run, make a temporary list of the exact files and review it. The simple examples below assume ordinary names ending in .jpg. If the images have mixed formats, use a broader pattern only after inspecting its expansion.

3. Make a basic contact sheet

Run the following command to place the images in four columns. -tile 4x sets the number of columns and lets montage calculate the required number of rows. -thumbnail 320x320 reduces each image to fit within that box while preserving its proportions. The -geometry value adds an eight-pixel gap around each tile and asks for the preferred tile size.

$ montage /path/to/photos/*.jpg \
    -thumbnail 320x320 \
    -tile 4x \
    -geometry 320x320+8+8 \
    -background white \
    /path/to/output/contact-sheet.png

This command reads the source images and writes contact-sheet.png. It does not alter the input files. The background is specified explicitly so transparent or irregularly sized images do not make the surrounding area depend on an implicit default.

Verify the result before opening it in a viewer:

$ identify /path/to/output/contact-sheet.png
/path/to/output/contact-sheet.png PNG ...

The exact line includes dimensions, colour depth and other build-dependent details. The useful checks are that the file exists, is a recognised PNG and has a non-zero size. The final dimensions depend on the number of inputs, the tile geometry and any labels.

4. Add filenames as labels

A sheet is easier to review when every tile identifies its source. Use -label before the inputs. The format string %f is replaced with each input's filename:

$ montage -label '%f' /path/to/photos/*.jpg \
    -thumbnail 320x320 \
    -tile 4x \
    -geometry 320x320+8+8 \
    -background white \
    /path/to/output/contact-sheet-labelled.png

Labels increase the height needed for each tile and are rendered using the available ImageMagick font configuration. If text is missing or looks wrong, check the installed font and the command's -font and -pointsize settings rather than changing the source images. For example:

$ montage -label '%f' -pointsize 14 /path/to/photos/*.jpg \
    -thumbnail 320x320 -tile 4x -geometry 320x320+8+8 \
    -background white /path/to/output/contact-sheet-labelled.png

Checkpoint

Compare the number of labels with the reviewed input list. A successful exit status only says that montage wrote an output; it does not prove that the shell selected the intended files.

5. Adjust the grid and output size

Change -tile when the sheet needs a different shape. -tile 2x makes two columns, while -tile 2x3 requests two columns and three rows. If there are more images than the requested grid can hold, do not assume that the remainder will fit where you want it. Use an open dimension such as 4x when the input count varies.

Keep -thumbnail and -geometry conceptually separate. The former changes the images being placed; the latter controls the preferred tile and border geometry. If you need one fixed canvas per tile, test the result with identify and adjust the geometry deliberately. Do not use a large geometry value as a substitute for checking the final file size: high-resolution inputs and labels can still produce a large output.

JPEG is useful for a compact photographic sheet, but it is lossy. PNG is a safer review format for sharp text, transparency or later editing:

$ identify /path/to/output/contact-sheet-labelled.png
$ montage -label '%f' /path/to/photos/*.jpg \
    -thumbnail 240x240 -tile 5x -geometry 240x240+6+6 \
    -background white /path/to/output/contact-sheet.jpg
$ identify /path/to/output/contact-sheet.jpg

6. Avoid overwriting a useful result

Warning

Output redirection is not involved here, but montage will replace an existing output path. Choose a new filename while testing. If you must replace a sheet, write a temporary result first and rename it only after verification:

$ montage -label '%f' /path/to/photos/*.jpg \
    -thumbnail 320x320 -tile 4x -geometry 320x320+8+8 \
    -background white /path/to/output/contact-sheet.png.new.png
$ identify /path/to/output/contact-sheet.png.new.png
$ mv /path/to/output/contact-sheet.png.new.png \
    /path/to/output/contact-sheet.png

The mv replaces the old sheet on the same filesystem. That replacement is the deliberate state-changing step. If the command or verification fails, leave the old sheet in place and remove the incomplete .new.png file after checking its path. Do not delete source images as part of cleanup.

7. Diagnose common failures

If montage says it cannot open a file, inspect the expanded paths and permissions:

$ ls -l /path/to/photos
$ test -r /path/to/photos/example.jpg && echo readable

If the sheet is unexpectedly sparse or has the wrong number of tiles, rerun the printf listing and count the inputs. A shell glob is expanded before montage starts, so montage cannot correct an overly broad or overly narrow pattern. If labels are absent, confirm that -label appears before the input files and that the output path is still last.

If ImageMagick reports a format or delegate error, keep the original files and test one input at a time. Some formats depend on optional delegates in the installed package. Use identify /path/to/one-file to separate an unreadable input from a montage layout problem. Do not weaken file permissions or run as root to hide an access error.

Done means

  • The installed ImageMagick version and executable were checked.
  • The shell's input list was reviewed before montage ran.
  • The contact sheet has the intended grid, thumbnail bounds and labels.
  • identify confirms that the output exists in the expected format.
  • Source images remain untouched, and replacement was done only after a temporary output passed verification.