lib/image.py
changeset 33 4943047bfcb5
parent 28 70b6c13d084f
equal deleted inserted replaced
32:cc2d9db311c0 33:4943047bfcb5
    19 #
    19 #
    20 
    20 
    21 import os, os.path
    21 import os, os.path
    22 
    22 
    23 import PIL.Image
    23 import PIL.Image
       
    24 
       
    25 import dexif
    24 
    26 
    25 import settings, utils, log
    27 import settings, utils, log
    26 from template import image as image_tpl
    28 from template import image as image_tpl
    27     
    29     
    28 class Image (object) :
    30 class Image (object) :
    65         # (w, h) tuple
    67         # (w, h) tuple
    66         self.img_size = None
    68         self.img_size = None
    67         
    69         
    68         # the ShortURL code for this image
    70         # the ShortURL code for this image
    69         self.shorturl_code = None
    71         self.shorturl_code = None
       
    72 
       
    73 	# EXIF data
       
    74 	self.exif_data = {}
    70 
    75 
    71         # what to use in the rendered templates, intended to be overridden by subclasses
    76         # what to use in the rendered templates, intended to be overridden by subclasses
    72         self.series_act = "add"
    77         self.series_act = "add"
    73         self.series_verb = "Add to"
    78         self.series_verb = "Add to"
    74     
    79     
   122             self.title = self.name
   127             self.title = self.name
   123         
   128         
   124         if utils.mtime(self.html_path) < self.timestamp :
   129         if utils.mtime(self.html_path) < self.timestamp :
   125             log.info("render %s.html", self.name)
   130             log.info("render %s.html", self.name)
   126 
   131 
       
   132             # parse the exif data from the file
       
   133             try :
       
   134                     self.exif_data = dexif.parse_exif(self.path)
       
   135             except dexif.ExifError, message:
       
   136                     log.warning("Reading EXIF data for %s failed: %s" % (self.filename, message))
       
   137                     self.exif_data = {}
       
   138 
       
   139 
   127             image_tpl.render_to(self.html_path,
   140             image_tpl.render_to(self.html_path,
   128                 stylesheet_url             = self.dir.inRoot('style.css'),
   141                 stylesheet_url             = self.dir.inRoot('style.css'),
   129                 title                      = self.title,
   142                 title                      = self.title,
   130                 breadcrumb                 = self.breadcrumb(),
   143                 breadcrumb                 = self.breadcrumb(),
   131                 
   144                 
   137                 
   150                 
   138                 filename                   = self.name,
   151                 filename                   = self.name,
   139                 img_size                   = self.img_size,
   152                 img_size                   = self.img_size,
   140                 file_size                  = self.filesize,
   153                 file_size                  = self.filesize,
   141                 timestamp                  = self.timestamp,
   154                 timestamp                  = self.timestamp,
       
   155 		exif_data		   = self.exif_data,
   142                 
   156                 
   143                 shorturl                   = self.dir.inRoot('s', self.shorturl_code),
   157                 shorturl                   = self.dir.inRoot('s', self.shorturl_code),
   144                 shorturl_code              = self.shorturl_code,
   158                 shorturl_code              = self.shorturl_code,
   145                 
   159                 
   146                 series_url                 = self.dir.inRoot('series/%s/%s' % (self.series_act, self.shorturl_code)),
   160                 series_url                 = self.dir.inRoot('series/%s/%s' % (self.series_act, self.shorturl_code)),