import sys
import glob
from shutil import rmtree,copytree
-from PIL import Image
-from libxmp import consts
-from libxmp import XMPFiles
from lxml import etree
from lxml.builder import ElementMaker
+from treecutter.image import Image
from treecutter import constants as const
self.uri = unicode(uri)
self.albumid = abs(hash(self.uri))
self.filelist = []
- self.filelist_thumb = []
- self.filelist_slider = []
-
- def format(self):
- for infile in self.filelist:
- size = (50, 50)
- outfile, ext = os.path.splitext(infile)
- outfile = outfile+"."+str(size[0])+"x"+str(size[1])+ext
- if not os.path.exists(outfile):
- im = Image.open(infile)
- im.thumbnail(size, Image.ANTIALIAS)
- im.save(outfile)
- self.filelist_thumb.append(outfile)
- size = (700, 438)
- outfile, ext = os.path.splitext(infile)
- outfile = outfile+"."+str(size[0])+"x"+str(size[1])+ext
- if not os.path.exists(outfile):
- im = Image.open(infile)
- im.thumbnail(size, Image.ANTIALIAS)
- bg = Image.new('RGBA', size, (0, 0, 0, 0))
- bg.paste(im,((size[0]-im.size[0])/2, (size[1]-im.size[1])/2))
- bg.save(outfile)
- self.filelist_slider.append(outfile)
def files(self):
d = self.uri
for root, subdir, files in os.walk(d):
for f in files:
- self.filelist.append(os.path.join(root,f))
+ img = Image(os.path.join(root,f))
+ if not img.generated():
+ self.filelist.append(img)
def db_xml(self):
db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
sl = db.itemizedlist(**{const.XML+"id": "slider"})
cnt = 0
- for fs, f in zip(self.filelist_slider, self.filelist):
+ for img in self.filelist:
cnt = cnt + 1
- xmpfile = XMPFiles(file_path=f)
- xmp = xmpfile.get_xmp()
- if xmp.does_property_exist(consts.XMP_NS_DC, 'description[1]'):
- cap = xmp.get_property(consts.XMP_NS_DC, 'description[1]')
- else:
- cap = "Beskrivning saknas"
- xmpfile.close_file()
+ caption = db.caption()
+ for p in img.caption().split('\n\n'):
+ caption.append(db.para(p))
+ link = db.para(db.link(img.infostr(),
+ **{const.XLINK+"href": img.filename()}))
+ caption.append(link)
sl.append(
db.listitem(db.mediaobject(
- db.imageobject(db.imagedata(fileref=fs)),
- db.caption(db.para(cap, db.link("[]",**{const.XLINK+"href": f})))),**{const.XML+"id": "p%x%d" % (self.albumid,cnt)}))
+ db.imageobject(db.imagedata(fileref=img.slider())),caption),
+ **{const.XML+"id": "p%x%d" % (self.albumid,cnt)}))
th = db.itemizedlist(**{const.XML+"id": "thumb"})
cnt = 0
- for f in self.filelist_thumb:
+ for img in self.filelist:
cnt = cnt + 1
- th.append(db.listitem(db.para(db.link(db.inlinemediaobject(db.imageobject(db.imagedata(fileref=f))),**{const.XLINK+"href": "#p%x%d" % (self.albumid, cnt)}))))
+ th.append(db.listitem(db.para(db.link(db.inlinemediaobject(
+ db.imageobject(db.imagedata(fileref=img.thumbnail()))),**{const.XLINK+"href": "#p%x%d" % (self.albumid, cnt)}))))
return db.informalfigure(sl,th,**{const.XML+"id": "box"})
def recursively_empty(e):
album = PhotoAlbum(argument)
album.files()
- album.format()
axml = album.db_xml()
# clean_db(axml)