--- /dev/null
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from dateutil.tz import *
+from datetime import datetime
+from dateutil.parser import parse
+
+import os
+import sys
+import Image
+
+from lxml import etree
+from lxml.builder import ElementMaker
+
+from treecutter import constants as const
+
+class Pic(object):
+ def __init__(self, picture, caption):
+ self.picture = picture
+ self.caption = caption
+ self.sizes = [(500,500),(800,800),(1024,1024)]
+ self.outfiles = []
+
+ def thumbnails(self):
+ infile = os.path.splitext(self.picture)
+ for size in self.sizes:
+ outfile = infile[0]+"-"+str(size[0])+infile[1]
+ if infile != outfile:
+ try:
+ im = Image.open(self.picture)
+ im.thumbnail(size, Image.ANTIALIAS)
+ im.save(outfile, im.format)
+ self.outfiles.append(outfile)
+ except IOError:
+ print "cannot create thumbnail for '%s'" % infile
+ self.outfiles.append(self.picture)
+
+ def db_xml(self):
+ webpic = self.outfiles[0]
+ imw = Image.open(webpic)
+ ww,dw = imw.size
+
+ db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
+
+ pics = db.para()
+ for f in self.outfiles:
+ im = Image.open(f)
+ w,d = im.size
+ pics.append(db.link(str(w)+"x"+str(d)+" ",**{const.XLINK+"href": f}))
+ #pics = list(', '.join(pics))
+ #pics.append(')')
+ # pics.insert(0,'Sizes (')
+ lst = db.mediaobject(
+ db.imageobject(
+ db.imagedata(fileref=webpic, width=str(ww), depth=str(dw))),
+ db.caption(db.para(self.caption),pics))
+ return lst
+
+if __name__ == "__main__":
+ for arg in sys.argv[1:]:
+ al = arg.split("=")
+ if al[0] == "lang":
+ lang = al[1]
+ if al[0] == "xptr":
+ argument = al[1]
+ p,c = argument.split("|")
+ pic = Pic(p,c)
+ pic.thumbnails()
+ pxml = pic.db_xml()
+ sys.stdout.write(etree.tostring(pxml,encoding='UTF-8',pretty_print=False))