degal/thumbnail.py
changeset 95 3b00bd676fc9
parent 85 7da934333469
child 115 d5aa320697df
equal deleted inserted replaced
94:676c1d201cfe 95:3b00bd676fc9
    17             
    17             
    18             `subdir` specifies the directory to store this thumbnail in.
    18             `subdir` specifies the directory to store this thumbnail in.
    19             `size` determines the target resolution of the output thumbnail.
    19             `size` determines the target resolution of the output thumbnail.
    20         """
    20         """
    21 
    21 
    22         # our file path
    22         # our file path, image name inside of the given subdir
    23         # XXX: this should be the binary fsname, not name
    23         super(Thumbnail, self).__init__(subdir, image.fsname)
    24         super(Thumbnail, self).__init__(subdir.subnode(image.name))
       
    25 
    24 
    26         # store
    25         # store
    27         self.image = image
    26         self.image = image
    28         self.size = size
    27         self.size = size
    29 
    28 
    30     def stale (self) :
    29     def stale (self) :
    31         """
    30         """
    32             Tests if this thumbnail is stale
    31             Tests if this thumbnail is stale
    33         """
    32         """
    34         
    33         
    35         return self.older_than(self.image)
    34         if self.image.older_than(self) :
       
    35             # both exist and this is newer
       
    36             return False
       
    37         
       
    38         else :
       
    39             # this thumb doesn't exist or is older
       
    40             return True
    36 
    41 
    37     def update (self) :
    42     def update (self) :
    38         """
    43         """
    39             Render new output thumbnail
    44             Render new output thumbnail
    40         """
    45         """
    45         # resample to given size
    50         # resample to given size
    46         thumb.thumbnail(self.size, resample=True)
    51         thumb.thumbnail(self.size, resample=True)
    47 
    52 
    48         # and write out
    53         # and write out
    49         thumb.save(self.path)
    54         thumb.save(self.path)
    50 
    55