diff -r e7855eefb4c7 -r 55cb7fc9c8fb degal/image.py --- a/degal/image.py Sun Jun 14 22:59:29 2009 +0300 +++ b/degal/image.py Sun Jun 14 23:43:40 2009 +0300 @@ -2,13 +2,10 @@ Per-image gallery state """ -from __future__ import with_statement - -import filesystem, format, thumbnail +import filesystem, format, thumbnail, exif from utils import lazy_load import PIL.Image -from lib import EXIF class Image (filesystem.File) : """ @@ -57,22 +54,13 @@ @lazy_load def exif (self) : """ - Loads the EXIF data for the image and returns as a dict of EXIF tag names -> values. + Loads the ExifHandler object for this image. Returns None if no exif data was found """ - # load - with self.open('rb') as fh : - # XXX: details=False? - exif = EXIF.process_file(fh) - - # empty dict -> no exif data - if exif : - return exif - - else : - return None + # look up using exif + return exif.load(self.config, self) @lazy_load def metadata (self) : @@ -87,20 +75,21 @@ size = self.img_size # build - metadata = dict({ - "File name": self.name, - "Resolution": "%dx%d" % size, - "File size": format.filesize(stat.st_size), - "Last modified": format.filetime(stat.st_mtime), - }) + metadata = [ + ("File name", self.name), + ("Resolution", "%dx%d" % size), + ("File size", format.filesize(stat.st_size)), + ("Last modified", format.filetime(stat.st_mtime)), + ] # optionally load Exif metadata - if self.config.with_exif : - exif = self.exif + if self.config.with_exif and self.exif : + exif_tag_name = dict(self.config.exif_tags) + exif_tags = (tag for tag, name in self.config.exif_tags) - # Get the wanted tags - metadata.update(dict( - (name, exif[tag]) for tag, name in self.config.exif_tags if exif and tag in exif + # merge the wanted tags + metadata.extend(( + (exif_tag_name[tag], value) for tag, value in self.exif.image_tags(exif_tags) )) return metadata