From 0352e45513762cbcf7f8441a7073be27a4293bc8 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 26 Mar 2016 17:15:18 +0100 Subject: Fixed error handling on image thumbnails. Replaced jquery-lazyload with jquery.lazy which provides an onError event handler. --- fbin.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'fbin.py') diff --git a/fbin.py b/fbin.py index 7339a26..138ea64 100755 --- a/fbin.py +++ b/fbin.py @@ -407,7 +407,7 @@ class Application(object): def static(self, environ, start_response, path): filename = path[1] - if not filename in ('style.css', 'no-thumbnail.png', 'favicon.ico', 'jquery-2.1.0.min.js', 'jquery.lazyload.min.js'): + if not filename in ('style.css', 'no-thumbnail.png', 'favicon.ico', 'jquery-2.1.0.min.js', 'jquery.lazy.min.js'): start_response('404 Not Found', []) return [] @@ -462,7 +462,15 @@ class Application(object): thumbfile = os.path.join(settings.thumb_directory, hash + '.jpg') if not os.access(thumbfile, os.F_OK): file = self.get_file(hash) - im = Image.open(file.get_path()) + try: + im = Image.open(file.get_path()) + except IOError: + # We can't generate a thumbnail for this file, just say it doesn't exist. + start_response('404 Not Found', []) + return [] + # Check for valid JPEG modes. + if im.mode not in ('1', 'L', 'RGB', 'RGBA', 'RGBX', 'CMYK', 'YCbCr'): + im = im.convert('RGB') im.thumbnail(settings.thumb_size, Image.ANTIALIAS) im.save(thumbfile) -- cgit v1.2.3