Simple thumbnail page generation script

Here is a little script I hacked together in a minute. I needed simple way to turn one dir of photos to a thumbnailed web page. And the photos needed to resize to a smaller size. Then I got an idea to add the timestamp in the lower right corner of every photo.

It uses the mighty Imagemagick tools to handle the photo editing.

And here is the script.

files = os.listdir('.')
date = sys.argv[1]

os.mkdir('thumbs')

for file in files:
  os.system("mogrify -resize 800x600 '%s'" % (file,))
  os.system("convert '%s' -fill white -undercolor '#0008' -gravity SouthEast -annotate +0+0 '   %s   ' '%s'" % (file, date, file))
  os.system("cp '%s' thumbs/" % (file,))
  os.system("mogrify -thumbnail 200x200 'thumbs/%s'" % (file,))

index = open('index.html', 'w+')
index.write('<html><header></heade><body>\n')

for file in files:
  index.write('<a href="%s"><img src="thumbs/%s" /></a>" % (file, file))
  index.write('</body></html>')
  index.close()

Note

2011-01-02 10:41 Re-published from old website