Permalink
Browse files

now regenerate when thumbnail is out of date

  • Loading branch information...
1 parent 30d2e40 commit cf5fb00b38e7b26e1e83767ab1c64cb4ef5b5c7a @trey0 trey0 committed with Intelligent Robotics Group Aug 31, 2011
Showing with 20 additions and 11 deletions.
  1. +20 −11 geocamLens/models.py
View
@@ -12,6 +12,7 @@
import random
import re
from cStringIO import StringIO
+import stat
import pytz
import PIL.Image
@@ -180,17 +181,25 @@ def getThumbnailUrl(self, width):
def makeThumbnail0(self, previewOriginalPath, thumbSize):
maxOutWidth, maxOutHeight = thumbSize
- if previewOriginalPath is not None and not os.path.exists(self.getThumbnailPath(maxOutWidth)):
- im = PIL.Image.open(previewOriginalPath)
- fullWidth, fullHeight = im.size
- thumbWidth, thumbHeight = self.calcThumbSize(fullWidth, fullHeight, maxOutWidth, maxOutHeight)
- try:
- im.thumbnail((thumbWidth, thumbHeight), PIL.Image.ANTIALIAS)
- except IOError, e:
- # fall back to resize
- im.resize((thumbWidth, thumbHeight), PIL.Image.ANTIALIAS)
- mkdirP(self.getDir())
- im.save(self.getThumbnailPath(maxOutWidth))
+ if previewOriginalPath is None:
+ return
+ thumbPath = self.getThumbnailPath(maxOutWidth)
+ if os.path.exists(thumbPath):
+ thumbMtime = os.stat(thumbPath)[stat.ST_MTIME]
+ fullMtime = os.stat(previewOriginalPath)[stat.ST_MTIME]
+ if fullMtime < thumbMtime:
+ return
+
+ im = PIL.Image.open(previewOriginalPath)
+ fullWidth, fullHeight = im.size
+ thumbWidth, thumbHeight = self.calcThumbSize(fullWidth, fullHeight, maxOutWidth, maxOutHeight)
+ try:
+ im.thumbnail((thumbWidth, thumbHeight), PIL.Image.ANTIALIAS)
+ except IOError, e:
+ # fall back to resize
+ im.resize((thumbWidth, thumbHeight), PIL.Image.ANTIALIAS)
+ mkdirP(self.getDir())
+ im.save(self.getThumbnailPath(maxOutWidth))
def makeThumbnail(self, thumbSize):
previewOriginalPath = self.getImagePath()

0 comments on commit cf5fb00

Please sign in to comment.