2 # -*- coding: utf-8 -*-
4 from dateutil.tz import *
5 from datetime import datetime
6 from dateutil.parser import parse
12 from lxml import etree
13 from lxml.builder import ElementMaker
15 from treecutter import constants as const
18 def __init__(self, picture, caption):
19 self.picture = picture
20 self.caption = caption
21 self.sizes = [(500,500),(800,800),(1024,1024)]
25 infile = os.path.splitext(self.picture)
26 for size in self.sizes:
27 outfile = infile[0]+"-"+str(size[0])+infile[1]
30 im = Image.open(self.picture)
31 im.thumbnail(size, Image.ANTIALIAS)
32 im.save(outfile, im.format)
33 self.outfiles.append(outfile)
35 print "cannot create thumbnail for '%s'" % infile
36 self.outfiles.append(self.picture)
39 webpic = self.outfiles[0]
40 imw = Image.open(webpic)
43 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
46 for f in self.outfiles:
49 pics.append(db.link(str(w)+"x"+str(d)+" ",**{const.XLINK+"href": f}))
50 #pics = list(', '.join(pics))
52 # pics.insert(0,'Sizes (')
55 db.imagedata(fileref=webpic, width=str(ww), depth=str(dw))),
56 db.caption(db.para(self.caption),pics))
59 if __name__ == "__main__":
60 for arg in sys.argv[1:]:
66 p,c = argument.split("|")
70 sys.stdout.write(etree.tostring(pxml,encoding='UTF-8',pretty_print=False))