move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
"""
State for thumbnails; derivates of Images
"""
import filesystem
import PIL.Image
class Thumbnail (filesystem.File) :
"""
A Thumbnail is a derivate of an Image, usually resized to some other size.
"""
def __init__ (self, image, subdir, size) :
"""
Initialize to link against the given `image`.
`subdir` specifies the directory to store this thumbnail in.
`size` determines the target resolution of the output thumbnail.
"""
# our file path
# XXX: this should be the binary fsname, not name
super(Thumbnail, self).__init__(subdir.subnode(image.name))
# store
self.image = image
self.size = size
def stale (self) :
"""
Tests if this thumbnail is stale
"""
return self.older_than(self.image)
def update (self) :
"""
Render new output thumbnail
"""
# load a copy of the PIL.Image, as .thumbnail mutates it
thumb = self.image.pil_image.copy()
# resample to given size
thumb.thumbnail(self.size, resample=True)
# and write out
thumb.save(self.path)