diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2016-03-26 17:15:18 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2016-03-26 17:15:18 +0100 |
commit | 0352e45513762cbcf7f8441a7073be27a4293bc8 (patch) | |
tree | e69c5f24272d82dbd9ade1cebf743fc7b1395f67 /fbin.py | |
parent | df5f964245d3d32c3c5cc56eb292f9aedc74572c (diff) |
Fixed error handling on image thumbnails.
Replaced jquery-lazyload with jquery.lazy which provides an onError
event handler.
Diffstat (limited to 'fbin.py')
-rwxr-xr-x | fbin.py | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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) |