From 54d678bc3312b05e2f73eec55243a7f55a0de05e Mon Sep 17 00:00:00 2001 From: Victor Hall Date: Mon, 28 Nov 2022 15:06:27 -0500 Subject: [PATCH] bug in compress img --- scripts/compress_img.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/compress_img.py b/scripts/compress_img.py index 97b46cf..e1a2641 100644 --- a/scripts/compress_img.py +++ b/scripts/compress_img.py @@ -151,10 +151,12 @@ def scan_path(queue, args): def shrink(img, args): """Shrink an image.""" - pixels = img.width * img.height - ratio = args.max_mp / pixels + hw = img.size + ratio = args.max_mp / (hw[0]*hw[1]) + newhw = (int(hw[0]*ratio**0.5), int(hw[1]*ratio**0.5)) + try: - return ImageOps.scale(img, ratio, Image.LANCZOS) + return img.resize(newhw, Image.BICUBIC) except Exception as err: inline(f"[!] Error Shrinking: {img.filename} - {err}", True) return img