rendered paste body#!/usr/bin/env pythonimport sys, os, globfrom os.path import *SIZE = (24, 24)COLS = 5DIR = "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("""<html><head> <style>a { color: #844900; text-decoration: none;}a:hover { color: #DD6900; text-decoration: underline;}a:visited { color: #b85b5a;}a img { border: 0px;}body { background-color: white; margin: 0; padding: 0; color: #333; text-align: center; font-family: monospace;}p { font-size: xx-small;}table { border: thin solid black; border-collapse: collapse; margin-left: auto; margin-right: auto;}td { border: thin solid black; background-color: white; padding-left: 5px; padding-right: 5px; padding-bottom: 5px; padding-top: 5px;} </style></head><body><table>""")out.write("<tr>")i = 1def 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("<td><a href='%s'><img src='%s'/></a></td>" % (f, thumb)) if i % COLS == 0: out.write("</tr><tr>") 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("</tr></table></body></html>")out.close()