See mkphotodir for a more sophisticated program to do similar work.
This program relies upon webc to do a certain amount of work. There is a copy of the program in the SupportBin directory of this archive.
The main program, mkcontact creates an index.html file based upon the photos in the current directory, and the template file specified by the --template command line argument. The --force command line argument builds a new index.html file even if it already exists. It also allows for directories to be processed even if the index.html file exists. The --noindex says to never make an index file. The --convert flag specifies the name of the convert program (from ImageMagick) and the thumbnail width is specified by --limit.
The second program, mkcontact.recent is used to find new directories which have photos but don't have index.html pages.