From ecb48ce6630f44eaecaf296c85a0cfce8aff4c67 Mon Sep 17 00:00:00 2001 From: thomas girod Date: Thu, 8 Aug 2024 17:50:23 +0200 Subject: [PATCH] fix error when uploading image with an alpha channel --- core/utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/utils.py b/core/utils.py index b336a125..b50578b0 100644 --- a/core/utils.py +++ b/core/utils.py @@ -96,10 +96,7 @@ def get_semester_code(d: Optional[date] = None) -> str: def scale_dimension(width, height, long_edge): - if width > height: - ratio = long_edge * 1.0 / width - else: - ratio = long_edge * 1.0 / height + ratio = long_edge / max(width, height) return int(width * ratio), int(height * ratio) @@ -107,8 +104,8 @@ def resize_image(im, edge, img_format): (w, h) = im.size (width, height) = scale_dimension(w, h, long_edge=edge) content = BytesIO() - # use the lanczos filter for antialiasing - im = im.resize((width, height), Resampling.LANCZOS) + # use the lanczos filter for antialiasing and discard the alpha channel + im = im.resize((width, height), Resampling.LANCZOS).convert("RGB") try: im.save( fp=content,