"""Run this script in the background while you're working on the
tutorial. Every five seconds, it scans for .pngs, .jpgs, and ..gifs
that have not yet been coverted to encapsulated postscript. If it
finds one, it converts it to an encapsulated postscript file of
the same name.
Requires the Python Imaging Library, a very common python library."""
import Image
import os
import time
import string
extensionsToConvert = [ 'png', 'gif', 'jpg' ]
def stripSuffix(s):
return s[:string.rfind(s, ".")]
def suffix(s):
return s[string.rfind(s, ".")+1:]
while 1:
filelist = os.listdir(".")
epsDict = {}
for f in filelist:
if suffix(f) == "eps":
epsDict[stripSuffix(f)] = 0
for f in filelist:
if suffix(f) in extensionsToConvert and \
not epsDict.has_key(stripSuffix(f)):
try:
im = Image.open(f)
except:
print "failed:", f
im.save(stripSuffix(f) + ".eps")
print "Converted " + f
time.sleep(5)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>