From dba64a00519915ea5ff4c8ae399aa2cc03e06fa3 Mon Sep 17 00:00:00 2001 From: Jake Charman Date: Wed, 5 Nov 2025 20:37:56 +0000 Subject: [PATCH] Add caching to resized images --- src/projects.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/projects.py b/src/projects.py index 97be9c1..bce9bba 100755 --- a/src/projects.py +++ b/src/projects.py @@ -151,6 +151,9 @@ def image(image_name: str) -> Response: if (w >= max_width and h >= max_height): return send_from_directory(md_directory, path.join('images', image_name)) + + if path.exists(path.join('images', f'{w}-{h}-{image_name}')): + return send_from_directory(md_directory, path.join('images', f'{w}-{h}-{image_name}')) req_size = [max_width, max_height] if w > 0: @@ -161,6 +164,7 @@ def image(image_name: str) -> Response: resized_img = BytesIO() the_image.thumbnail(tuple(req_size)) the_image.save(resized_img, format=the_image.format) + the_image.save(path.join(md_directory, 'images', f'{w}-{h}-{image_name}'), the_image.format) response = make_response(resized_img.getvalue()) response.headers.set('Content-Type', f'image/{the_image.format}')