From a1c2e9fb199a295ddd080c8e4343ee0e192de499 Mon Sep 17 00:00:00 2001 From: mungai-njoroge Date: Mon, 28 Aug 2023 12:43:20 +0300 Subject: [PATCH] maintain thumbnail aspect ratio in taglib.extract_thumb --- app/lib/taglib.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/lib/taglib.py b/app/lib/taglib.py index 007464c..61e92cb 100644 --- a/app/lib/taglib.py +++ b/app/lib/taglib.py @@ -36,9 +36,12 @@ def extract_thumb(filepath: str, webp_path: str, overwrite=False) -> bool: sm_tsize = Defaults.SM_THUMB_SIZE def save_image(img: Image.Image): + width, height = img.size + ratio = width / height + img.save(original_img_path, "webp") - img.resize((tsize, tsize), Image.ANTIALIAS).save(lg_img_path, "webp") - img.resize((sm_tsize, sm_tsize), Image.ANTIALIAS).save(sm_img_path, "webp") + img.resize((tsize, int(tsize / ratio)), Image.ANTIALIAS).save(lg_img_path, "webp") + img.resize((sm_tsize, int(sm_tsize / ratio)), Image.ANTIALIAS).save(sm_img_path, "webp") if not overwrite and os.path.exists(sm_img_path): img_size = os.path.getsize(sm_img_path)