From ff3d5ef48d44e536c49a5e12a8f4d7fa61ee367c Mon Sep 17 00:00:00 2001 From: Jake Charman Date: Mon, 3 Feb 2025 19:48:14 +0000 Subject: [PATCH] Add fallback for images PIL can't handle --- src/projects.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/projects.py b/src/projects.py index c72d0e2..eb9bbb2 100755 --- a/src/projects.py +++ b/src/projects.py @@ -9,7 +9,7 @@ from glob import glob from datetime import datetime from index import app from bs4 import BeautifulSoup -from PIL import Image +from PIL import Image, UnidentifiedImageError from io import BytesIO md_directory = path.join(path.realpath(path.dirname(__file__)), path.normpath('projects/')) @@ -133,6 +133,9 @@ def image(image): the_image = Image.open(path.join(md_directory, 'images', image)) except FileNotFoundError: return Response(status=404) + except UnidentifiedImageError: + return send_from_directory(md_directory, path.join('images', image)) + max_width, max_height = the_image.size if (w >= max_width and h >= max_height):