#!/usr/bin/env python import sys, os, glob from os.path import * SIZE = (24, 24) COLS = 5 DIR = "thumbnails" HTML = "thumbnails.html" try: os.makedirs(DIR) except Exception, msg: if not exists(DIR): print "Unable to create thumbnails directory:%s (%s)" % (DIR, msg) sys.exit(-1) if exists(HTML): print "Thumbnail file %s already exists, stopping" % HTML sys.exit(-1) out = file(HTML, 'w') out.write(""" """) out.write("") i = 1 def output_dir(d): for f in os.listdir(d): name = join(d, f) if isfile(name): if name.endswith("png") or name.endswith("jpg"): output_file(name) else: output_dir(name) def output_file(f): global i thumb = join(DIR, basename(f)) if not exists(thumb): print >> sys.stderr, "Thumbnailing", thumb if SIZE[0] == "" and SIZE[1] == "": os.system("ln -s '%s' '%s'" % (f, thumb)) else: os.system("convert '%s' -resize %sx%s '%s'" % (f, SIZE[0], SIZE[1], thumb)) out.write("" % (f, thumb)) if i % COLS == 0: out.write("") i += 1 for arg in sys.argv[1:]: if isfile(arg): if arg.endswith("png") or arg.endswith("jpg"): output_file(arg) else: output_dir(arg) out.write("
") out.close()