pnmindex
Create image index file from multiple images
TLDR
Produce an image containing thumbnails of the specified images in a grid
Specify the size of the (quadratic) thumbnails
Specify the number of thumbnails per row
Specify the maximum number of colors in the output
SYNOPSIS
pnmindex [options] [pnmfiles...]
PARAMETERS
-width N
Sets the width of the thumbnail images to N pixels.
-height N
Sets the height of the thumbnail images to N pixels.
-cols N
Specifies the number of columns in the HTML table.
-rows N
Specifies the maximum number of rows per page in the HTML table. If more images exist, multiple pages are generated.
-output filename
Names the main HTML output file. Defaults to index.html or outputs to standard output if - is specified.
-ext ext
Sets the file extension for generated thumbnails (e.g., jpg, png). Requires the corresponding Netpbm converter.
-relative
Uses relative paths for image links in the HTML, suitable for local browsing or deployment to a web server in the same structure.
-title string
Sets the title of the HTML page, displayed in the browser's title bar.
-desc string
Sets a description for the HTML page, displayed below the title on the page.
-verbose
Prints progress messages to standard error during execution, useful for debugging or monitoring long processes.
-jpeg
Generates JPEG format thumbnails. This is often the default if cjpeg is available.
-text
Generates a text-only index without any thumbnail images, listing filenames and possibly other details.
-light
Uses a light background color scheme for the HTML page.
-dark
Uses a dark background color scheme for the HTML page.
-link url
Links thumbnails to the specified url or the original image file by default. Can be used for external links.
-sort
Sorts images by filename alphabetically before processing.
-sortsize
Sorts images by their file size.
-sortdate
Sorts images by their modification date, from oldest to newest.
-rsort
Reverses the sort order specified by -sort, -sortsize, or -sortdate.
-page-size N
Sets the maximum number of thumbnails to include per HTML page.
-page-prefix prefix
Sets the filename prefix for additional HTML pages generated when -page-size is used.
-thumbnails-only
Generates only the thumbnail files, skipping the HTML index page generation.
-url-prefix prefix
Adds a prefix to the URLs for original images in the HTML, useful for hosting images in a specific directory.
DESCRIPTION
pnmindex is a utility from the Netpbm package designed to generate HTML index pages from a collection of PNM (Portable Anymap) image files. It automatically creates thumbnail images for each input image and embeds them into an HTML table, with links to the original images. This command is particularly useful for quickly generating a web-based gallery of images without manual HTML coding.
Users can customize various aspects of the output, including the dimensions of the thumbnails, the number of columns and rows in the HTML layout, page title, description, and the color scheme. It supports generating multiple HTML pages if the number of images exceeds a specified limit per page. While pnmindex primarily works with PNM files, it can be integrated with other Netpbm tools to process images in different formats by converting them to PNM first.
CAVEATS
pnmindex expects its input to be in one of the PNM formats (PBM, PGM, or PPM). If your images are in other formats (like JPEG, PNG, or GIF), you will need to convert them to PNM first using other Netpbm utilities such as djpeg (for JPEG to PPM) or pngtopnm (for PNG to PPM).
Generating thumbnails, especially for a large number of high-resolution images, can be CPU and disk I/O intensive. The generated HTML is functional but basic, suitable for quick indexing rather than complex web design. The command may create temporary files in the current directory or /tmp during processing.
TYPICAL USAGE WORKFLOW
To use pnmindex effectively with common image formats, you often need to pipe the output of a conversion utility to pnmindex, or convert images to PNM first.
A common approach for JPEG files would be to convert them to PNM and then pass the PNM filenames to pnmindex:mkdir pnm_tmp
for f in *.jpg; do djpeg "$f" > pnm_tmp/"${f%.jpg}.pnm"; done
pnmindex -width 150 -height 100 -cols 4 -output gallery.html pnm_tmp/*.pnm
rm -r pnm_tmp
A simpler example for already existing PNM files:pnmindex -width 150 -height 100 -cols 4 -output gallery.html *.ppm *.pgm
This command generates an HTML file named gallery.html with thumbnails of 150x100 pixels, arranged in 4 columns, for all PPM and PGM files in the current directory.
OUTPUT THUMBNAIL FORMATS
By default, pnmindex generates JPEG thumbnails if the cjpeg utility is available. You can specify a different output format using the -ext option (e.g., -ext png
), provided the corresponding Netpbm converter (like pnmtopng) is installed and accessible in your system's PATH. If the specified extension's converter is not found, pnmindex may fall back to its default or report an error.
HISTORY
pnmindex is an integral part of the Netpbm project, a suite of graphics utilities that originated from the Pbmplus package developed by Jef Poskanzer in the late 1980s. Netpbm tools are known for their simplicity, pipeline-friendliness, and ability to convert and manipulate a wide array of image formats using the PNM (Portable Anymap) intermediate format. pnmindex has evolved within this ecosystem, adapting to various system environments and image processing needs over decades, maintaining its core functionality of creating simple, navigable image indexes.