""" this script takes a list of image files and makes an HTML index page for them includign thumbnails. run this script like: time python photo-gallery.py *.JPG N.B. this script relies on the ImageMagick programs being installed. in particular the 'convert' program must be in your search path. author: chad clark email: chad.clark _AT_ gmail _DOT_ com web: http://superfrink.net/ created: 2007-02-17 $Id$ """ import commands import os import re import shutil import string import sys import time # -- globals ----------------------------------------------------- THUMBNAIL_DIRECTORY = "thumbnails" INDEX_FILE = "index.htm" # -- subroutines ------------------------------------------------- def get_thumb_file_name(dir, file): """ get the name of a thumbnail file based on the name of the original file """ return dir + "/" + file def create_thumbnail(thumb_dir, file): """ take a file and create a thumbnail file for it """ print "Creating thumbnail for %s ." % file thumb_file_name = get_thumb_file_name(thumb_dir, file) # if there is a thumbnail file move it aside if os.path.exists(thumb_file_name): date_str = time.strftime("%Y-%m-%d_%H-%M-%S",time.localtime(time.time())) new_file = thumb_file_name + "." + date_str print "move " + thumb_file_name + " " + new_file shutil.move(thumb_file_name, new_file) cmd_line = "convert -thumbnail 300x300 %s %s" % (file, thumb_file_name) #print cmd_line (cmd_status, cmd_output) = commands.getstatusoutput(cmd_line) def make_html_index(thumb_dir, file_list): print "\nCreating index.\n" # if there is an index file move it aside if os.path.exists(INDEX_FILE): date_str = time.strftime("%Y-%m-%d_%H-%M-%S",time.localtime(time.time())) new_file = INDEX_FILE + "." + date_str #print "move " + INDEX_FILE + " " + new_file shutil.move(INDEX_FILE, new_file) # create the index file fh = open(INDEX_FILE, "w") try: fh.write("\n") fh.write("
\n") fh.write("\n") fh.write("\n") fh.write("\n") fh.write(" " % file) fh.write("" % get_thumb_file_name(thumb_dir, file) ) fh.write("\n") fh.write(" | \n") count_this_line += 1 fh.write("