This is the program I use to generate and maintain my image gallery. It requires Python and the Python Imaging Library.

It seems like everyone's written one of these. This one's mine.

The program generates only static HTML. Thumbnails link directly to their respective pictures, not to another web page with the picture inside. Medium-sized versions of pictures are generated when the original picture is bigger than a certain threshold (see medium_size).

The program reads a file (by default gallery.def) in the current directory. The file may contain variable definitions, image references, links, and comments.

Variable definitions

A variable definition looks like

set name = value

You can set the following variables to alter the behavior of the program:

The name of the output file. By default "index.html".
The title of the gallery. By default "Gallery".
The maximum width in pixels of the table holding the images. By default 700.
The width in pixels of each cell in the table. By default 200.
The height in pixels of each cell. By default 200.
The padding in pixels around each image. By default 0.
The spacing in pixels around each cell. By default 5.
The maximum size of any side of a medium-sized image. By default 800.
HTML inserted at the top of the gallery in a little box.
HTML inserted at the bottom of the gallery.

Image references

An image reference looks like

image filename description

This causes the program to generate a thumbnail of the image and include it in the output with description. description may be omitted. If filename is image.jpg, the name of the thumbnail file will be image-sm.jpg. If a thumbnail already exists and is the right size, it will not be regenerated.

If any dimension of the image is greater than medium_size, a medium-sized image is generated and linked to instead. The original image is never modified. If filename is image.jpg, the name of the medium-sized image will be image-md.jpg.

If your file name contains spaces, you may surround it with double quotes.


A link looks like

link filename

This will create a link to another gallery defined in filename. The link text will be the title of the linked gallery. The linked gallery will have a link back to the linking gallery.

Linked galleries inherit the values of the linking gallery's variables, except prologue and epilogue.


A comment looks like

# Comment

The # must be the first non-whitespace character on the line.

Command line

Run, giving it the names of your gallery definition files as arguments. If you don't provide any, the program will look for gallery.def. accepts these command-line flags:

-i dir, --input dir
Read input files relative to dir. By default the current directory.
-o dir, --output dir
Write output files to a directory tree rooted at dir. By default the current directory.
-f, --force
Force regeneration of thumbnails and medium-sized images.
-n, --dry-run
Don't actually write any files or create any directories.


For examples see my image gallery. For every index.html in the directory tree there is a gallery.def that was used to generate it.

Updating a gallery on a remote server is easy with rsync. Use something like rsync -v -r -l -t -e ssh --delete ./ user@host:/var/httpd/images/