From 0affc7f4fb643810106c40c7394de17c1c486e57 Mon Sep 17 00:00:00 2001 From: Amadej Kastelic Date: Sat, 5 Oct 2024 20:48:18 +0200 Subject: [PATCH] Limit number of images in galleries (#15) --- bot/common/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bot/common/utils.py b/bot/common/utils.py index e3ba56b..09a3bf5 100644 --- a/bot/common/utils.py +++ b/bot/common/utils.py @@ -69,8 +69,13 @@ def recover_from_db_error(exc: Exception): django_db.close_old_connections() -def combine_images(image_fps: typing.List[str | io.BytesIO], gap: int = 10, quality: int = 85) -> io.BytesIO: - images = [pil_image.open(path) for path in image_fps] +def combine_images( + image_fps: typing.List[str | io.BytesIO], + gap: int = 10, + quality: int = 85, + max_images: int = 3, +) -> io.BytesIO: + images = [pil_image.open(path) for path in image_fps[:max_images]] widths, heights = zip(*(im.size for im in images)) new_image = pil_image.new('RGBA', (sum(widths), max(heights)))