--- a/degal/render.py Fri Jun 05 19:29:04 2009 +0300
+++ b/degal/render.py Fri Jun 05 19:30:15 2009 +0300
@@ -4,8 +4,6 @@
import PIL.Image
-import os.path
-
class RenderMachine (object) :
"""
RAWR! I'm the render machine!
@@ -20,11 +18,16 @@
self.config = config
- def render_out (self, img, size, out_path) :
+ def render_out (self, image, size, file) :
"""
- Creates a thumbnail from the given PIL.Image of the given size, and saves it at out_path.
+ Creates a thumbnail from the given Image of the given `size`, and saves it at `out`.
+
+ Returns the file for convenience
"""
+ # load the PIL.Image
+ img = image.load_image()
+
# we need to create a copy, as .thumbnail mutates the Image
img_out = img.copy()
@@ -32,20 +35,23 @@
img_out.thumbnail(size, resample=True)
# and write out
- img_out.save(out_path)
+ img_out.save(file.path)
- def render_img (self, img, dirname, filename) :
+ return file
+
+ def render_lazy (self, image, size, out) :
"""
- Renders new thumbnails/previews from the given loaded image and filename based on the current configuration.
-
- Note: this does not check for the existance of the thumbs/previews subdirs!
+ Renders the given image with render_out if `out` does not yet exist or is older than image.
"""
- # once for each size
- for subdir, size in (
- (self.config.thumb_dir, self.config.thumb_size),
- (self.config.preview_dir, self.config.preview_size)
- ) :
- # resize and write out
- self.render_out(img, size, os.path.join(dirname, subdir, filename)
+ # stat the output file
+ out_stat = out.stat(soft=True)
+ # compare
+ if not out_stat or out_stat.st_mtime < image.load_stat().st_mtime :
+ # render anew
+ return self.render_out(image, size, file)
+
+ else :
+ # already rendered
+ return file