"""photoclip.py This program makes a simple thumbnail PDF file for images captured on a Kodak DC280 digital camera. Requires the Python Image Library: http://www.pythonware.com/products/pil/index.htm Requires the now-dormant (but still functional) piddle library: http://sourceforge.net/projects/piddle/ Released into the public domain by Steve Holden (steve at holdenweb.com). $Revision: 2 $ $Date: 1/07/05 6:22a $ """ from piddle import * from piddlePDF import PDFCanvas, Font import PIL.Image import os.path, sys, glob, getopt def usage(): print """ Usage: photoclip.py [options] files Options: -h --help Print this text -o file --output file Send output to named file Default output is to PhotoClips.pdf in current directory """ MAXLINE = 8 MAXCOL = 4 LINEHEIGHT = 100 COLWIDTH = 140 LEFTMARGIN = 45 TOPMARGIN = 45 try: opts, args = getopt.getopt(sys.argv[1:], "ho:", ["help", "output="]) except getopt.GetoptError: # print help information and exit: usage() sys.exit(2) output = "PhotoClips.pdf" for o, a in opts: if o in ("-h", "--help"): usage() sys.exit() if o in ("-o", "--output"): output = a fntLarge = Font(face="helvetica", size=16, bold=1) fntMedium = Font(face="helvetica", size=12, bold=1) fntSmall = Font(face="helvetica", size=8, bold=0) imagename = [] for filepat in sys.argv[1:]: for infile in glob.glob(filepat): imagename.append(infile) imagename.sort() lineno = MAXLINE+1 colno = MAXCOL+1 pageno = 0 print "output:", output out = PDFCanvas(name=output) for i in range(len(imagename)): if colno >= MAXCOL: lineno = lineno+1 colno = 0 if lineno >= MAXLINE: lineno = 0 colno = 0 if pageno > 0: out.clear() pageno = pageno +1 print imagename[i]; sys.stdout.flush() im = PIL.Image.open(imagename[i]) imx = colno*COLWIDTH+LEFTMARGIN imy = lineno*LINEHEIGHT+TOPMARGIN out.drawImage(im.resize((220,146)), imx, imy, imx+109, imy+72) out.drawString(os.path.basename(imagename[i]), imx, imy+80, fntSmall) colno = colno +1 out.flush() out.save()