From 3bc0df3881be00bb1ad488a94ad2d6b560a7bb24 Mon Sep 17 00:00:00 2001 From: GeoffreyCoulaud Date: Wed, 14 Jun 2023 17:23:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Change=20image=20composition=20l?= =?UTF-8?q?ogic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/managers/online_cover_manager.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/store/managers/online_cover_manager.py b/src/store/managers/online_cover_manager.py index 736e6c6..fa82d06 100644 --- a/src/store/managers/online_cover_manager.py +++ b/src/store/managers/online_cover_manager.py @@ -92,14 +92,14 @@ class OnlineCoverManager(Manager): with Image.open(image_path) as pil_image: width, height = pil_image.size - # Composite the image if its aspect ratio differs too much - # (allow the side that is smaller to be stretched by a small percentage) - max_diff_proportion = 0.12 - scale = min(cover_width / width, cover_height / height) - width_diff = (cover_width - (width * scale)) / cover_width - height_diff = (cover_height - (height * scale)) / cover_height - diff = width_diff + height_diff - if diff < max_diff_proportion: + # Composite if the image is shorter and the stretch amount is too high + aspect_ratio = width / height + target_aspect_ratio = cover_width / cover_height + is_taller = aspect_ratio < target_aspect_ratio + resized_height = height / width * cover_width + stretch = 1 - (resized_height / cover_height) + max_stretch = 0.12 + if is_taller or stretch <= max_stretch: save_cover(game.game_id, resize_cover(image_path)) else: self.save_composited_cover(