Commit 097323ef authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

FSController.thumbnail: handle unreadable images more gracefully

parent 6654d660
......@@ -106,6 +106,8 @@ class FSController(AbstractController):
fs = self.get('fs')
self.release_database()
contents = fs.thumbnail(path, int(width), int(height))
if contents is None:
raise cherrypy.HTTPError(404, "Image is inaccessible or corrupted")
cherrypy.response.headers['Content-Type'] = "image/jpeg"
contents = StringIO.StringIO(contents)
return file_generator(contents)
......
......@@ -658,7 +658,10 @@ class FileSystem(object):
path = self.expand(path)
if HAVE_PIL:
output = StringIO()
img = Image.open(path).convert('RGB')
try:
img = Image.open(path).convert('RGB')
except IOError:
return None
img.thumbnail((width, height), Image.ANTIALIAS)
img.filter(ImageFilter.SHARPEN)
img.save(output, "JPEG")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment