From 66a1ba46c33342ed73b05c33924aa2819818c912 Mon Sep 17 00:00:00 2001 From: Jean-Marie PLACE Date: Fri, 21 Jan 2022 23:25:02 +0100 Subject: [PATCH] convert to RGB (from ARGB) when saving as JPEG --- app/views/scodoc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/scodoc.py b/app/views/scodoc.py index 02bc1fb11..394dfe833 100644 --- a/app/views/scodoc.py +++ b/app/views/scodoc.py @@ -266,14 +266,16 @@ def _return_logo(name="header", dept_id="", small=False, strict: bool = True): suffix = logo.suffix if small: with PILImage.open(logo.filepath) as im: - im.thumbnail(SMALL_SIZE) - stream = io.BytesIO() # on garde le même format (on pourrait plus simplement générer systématiquement du JPEG) fmt = { # adapt suffix to be compliant with PIL save format "PNG": "PNG", "JPG": "JPEG", "JPEG": "JPEG", }[suffix.upper()] + if fmt == "JPEG": + im = im.convert("RGB") + im.thumbnail(SMALL_SIZE) + stream = io.BytesIO() im.save(stream, fmt) stream.seek(0) return send_file(stream, mimetype=f"image/{fmt}")