From 0973e4f3616f4e41f15bac9c0aa9e5c8f27939a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 7 Apr 2010 19:38:37 +0200 Subject: Screenshots --- helper.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'helper.py') diff --git a/helper.py b/helper.py index ec7950b..552c526 100644 --- a/helper.py +++ b/helper.py @@ -1,5 +1,8 @@ import web import os +import Image + +opj = os.path.join APPDIR = os.path.dirname(os.path.abspath(__file__)) def appdir (*args): @@ -11,3 +14,36 @@ def url (path): def toJS (ls): ls = ("'%s':'%s'" % x for x in ls) return "{ %s }" % ", ".join(ls) + +def getImages (path, tmpPath, size): + if path[0] != '/': path = '/' + path + if tmpPath[0] != '/': tmpPath = '/' + tmpPath + + + appPath = appdir(path[1:]) + appTPath = appdir(tmpPath[1:]) + + for f in sorted(os.listdir(appPath)): + if not f.endswith(".png"): continue + + thumbName = "thumb-" + f + imgUrl = url(opj(path, f)) + thumbUrl = url(opj(tmpPath, thumbName)) + + imgPath = opj(appPath, f) + thumbPath = opj(appTPath, thumbName) + + if (not os.path.exists(thumbPath)) or \ + os.stat(imgPath).st_mtime > os.stat(thumbPath).st_mtime: + im = Image.open(imgPath) + im.thumbnail(size, Image.ANTIALIAS) + im.save(thumbPath) + + descName = f + ".desc" + desc = None + + if os.path.exists(opj(appPath, descName)): + with open(opj(appPath, descName)) as d: + desc = d.read().strip() + + yield (imgUrl, thumbUrl, desc) -- cgit v1.2.3