From 5d266835d0589e9e8b3c26aadc3a9a953a2562ee Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 6 Mar 2023 22:49:34 +0200 Subject: [PATCH] print to console when size after conversion is higher than size before --- files/helpers/media.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/files/helpers/media.py b/files/helpers/media.py index 583c3289c..72e0fd741 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -171,6 +171,7 @@ def process_image(filename:str, v, resize=0, trim=False, uploader_id:Optional[in try: with Image.open(filename) as i: + oldformat = i.format params = ["magick"] if resize == 99: params.append(f"{filename}[0]") else: params.append(filename) @@ -197,8 +198,14 @@ def process_image(filename:str, v, resize=0, trim=False, uploader_id:Optional[in "Please convert it to WEBP elsewhere then upload it again.")) return None + size_after_conversion = os.stat(filename).st_size + if size_after_conversion > size: + print(STARS, flush=True) + print(f'{filename}: {oldformat}@{size} -> WEBP@{size_after_conversion}', flush=True) + print(STARS, flush=True) + if resize: - if os.stat(filename).st_size > MAX_IMAGE_SIZE_BANNER_RESIZED_MB * 1024 * 1024: + if size_after_conversion > MAX_IMAGE_SIZE_BANNER_RESIZED_MB * 1024 * 1024: remove_media(filename) if has_request: abort(413, f"Max size for site assets is {MAX_IMAGE_SIZE_BANNER_RESIZED_MB} MB")