Commit cc51d808 authored by fred's avatar fred

thumbnails: return transparent pixel as data URI if missing image

parent 05df31e8
......@@ -15,7 +15,11 @@ def thumbnail(image, size='100x100'):
# defining the size
x, y = [int(x) for x in size.split('x')]
# defining the filename and the miniature filename
filehead, filetail = os.path.split(image.path)
try:
filehead, filetail = os.path.split(image.path)
except ValueError:
# return transparent pixel if the image doesn't actually exist
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='
basename, format = os.path.splitext(filetail)
if format.lower() not in ('.jpg', '.jpeg'):
format = '.png'
......
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