🎨 Change image composition logic
This commit is contained in:
@@ -92,14 +92,14 @@ class OnlineCoverManager(Manager):
|
|||||||
with Image.open(image_path) as pil_image:
|
with Image.open(image_path) as pil_image:
|
||||||
width, height = pil_image.size
|
width, height = pil_image.size
|
||||||
|
|
||||||
# Composite the image if its aspect ratio differs too much
|
# Composite if the image is shorter and the stretch amount is too high
|
||||||
# (allow the side that is smaller to be stretched by a small percentage)
|
aspect_ratio = width / height
|
||||||
max_diff_proportion = 0.12
|
target_aspect_ratio = cover_width / cover_height
|
||||||
scale = min(cover_width / width, cover_height / height)
|
is_taller = aspect_ratio < target_aspect_ratio
|
||||||
width_diff = (cover_width - (width * scale)) / cover_width
|
resized_height = height / width * cover_width
|
||||||
height_diff = (cover_height - (height * scale)) / cover_height
|
stretch = 1 - (resized_height / cover_height)
|
||||||
diff = width_diff + height_diff
|
max_stretch = 0.12
|
||||||
if diff < max_diff_proportion:
|
if is_taller or stretch <= max_stretch:
|
||||||
save_cover(game.game_id, resize_cover(image_path))
|
save_cover(game.game_id, resize_cover(image_path))
|
||||||
else:
|
else:
|
||||||
self.save_composited_cover(
|
self.save_composited_cover(
|
||||||
|
|||||||
Reference in New Issue
Block a user