maintain thumbnail aspect ratio in taglib.extract_thumb

This commit is contained in:
mungai-njoroge 2023-08-28 12:43:20 +03:00
parent 9972f64e8c
commit a1c2e9fb19

View File

@ -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)