Added use of ImageInfo

Mon, 17 Nov 2008 04:33:42 +0000

author
andy
date
Mon, 17 Nov 2008 04:33:42 +0000
changeset 7
3c6914b3cfae
parent 6
fffee8292ba7
child 8
209609a6c525

Added use of ImageInfo

emin file | annotate | diff | comparison | revisions
     1.1 --- a/emin	Mon Nov 17 02:36:44 2008 +0000
     1.2 +++ b/emin	Mon Nov 17 04:33:42 2008 +0000
     1.3 @@ -119,6 +119,12 @@
     1.4          self.path = None
     1.5          self.x = None
     1.6          self.y = None
     1.7 +    def _setsize(self, sizetuple):
     1.8 +        self.x = sizetuple[0]
     1.9 +        self.y = sizetuple[1]
    1.10 +    def _getsize(self):
    1.11 +        return self.x, self.y
    1.12 +    size = property(_getsize, _setsize)
    1.13  
    1.14  
    1.15  ## Go to the gallery directory and test if it's writeable
    1.16 @@ -158,8 +164,11 @@
    1.17  
    1.18  
    1.19  ## Make thumbnails if needed
    1.20 +THUMBDIR = "thumbs"
    1.21 +thumbdir = opts.OUTDIR
    1.22 +thumbsinfo = {}
    1.23  try:
    1.24 -    thumbdir = os.path.join(opts.OUTDIR, "thumbs")
    1.25 +    thumbdir = os.path.join(opts.OUTDIR, THUMBDIR)
    1.26      if not os.path.isdir(thumbdir):
    1.27          logging.info("Making thumbs dir in %s" % thumbdir)
    1.28          os.makedirs(thumbdir)
    1.29 @@ -167,18 +176,24 @@
    1.30      logging.error("Problem when making thumbnails dir... exiting")
    1.31      #traceback.print_exc()
    1.32      sys.exit(1)
    1.33 +
    1.34  try:
    1.35      for pic in pics:
    1.36          ## TODO: Un-hard-code PNG thumb format
    1.37 -        thumbpic = os.path.join(opts.OUTDIR, "thumbs", pic + ".png")
    1.38 -        if opts.FORCE or not os.access(thumbpic, os.R_OK) \
    1.39 -                or os.stat(thumbpic).st_mtime > os.stat(pic).st_mtime:
    1.40 +        thumbpic = pic + ".png"
    1.41 +        thumbpath = os.path.join(thumbdir, thumbpic)
    1.42 +        if opts.FORCE or not os.access(thumbpath, os.R_OK) \
    1.43 +                or os.stat(thumbpath).st_mtime > os.stat(pic).st_mtime:
    1.44              logging.debug("Making new thumbnail %s for %s (max height %d)" % \
    1.45 -                          (thumbpic, pic, opts.THUMB_HEIGHT))
    1.46 +                          (thumbpath, pic, opts.THUMB_HEIGHT))
    1.47              thumbimg = PILI.open(os.path.join(opts.SRCDIR, pic), "r")
    1.48              thumbimg.thumbnail((100000000, opts.THUMB_HEIGHT), resample=PILI.ANTIALIAS)
    1.49 +            info = ImageInfo()
    1.50 +            info.path = thumbpic
    1.51 +            info.size = thumbimg.size
    1.52 +            thumbsinfo[thumbpic] = info
    1.53              #thumbimg.show()
    1.54 -            thumbimg.save(thumbpic)
    1.55 +            thumbimg.save(thumbpath)
    1.56  except Exception, e:
    1.57      logging.warning("Problem when making thumbnail... exiting")
    1.58      #traceback.print_exc()
    1.59 @@ -281,11 +296,9 @@
    1.60  
    1.61      PAGEPICS = pics[pics_start, pics_end]
    1.62      PAGEPICNUMS = range(len(pics))
    1.63 -    ## Generalise this dir
    1.64 -    THUMBDIR = "thumbs"
    1.65      PAGETHUMBS = [os.path/join(THUMBDIR, t) for t in thumbs[pics_start, pics_end]]
    1.66      ## TODO: Build a list of thumb dims during the minimisation process, using ImageInfo
    1.67 -    #PAGETHUMBDIMS = [(getWidth(t), getHeight(t)) ) for t in PAGETHUMBS]
    1.68 +    PAGETHUMBDIMS = [(t), getHeight(t)) ) for t in PAGETHUMBS]
    1.69  
    1.70      ## Use template file
    1.71      ## TODO

mercurial