From 11f6e2dca668230dd78db734ee63eedac6de37c2 Mon Sep 17 00:00:00 2001 From: alpha-nerd-nomyo Date: Wed, 24 Sep 2025 18:10:17 +0200 Subject: [PATCH] data-url handling and removing alpha channel in images --- router.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/router.py b/router.py index 13f1abc..3bd9f48 100644 --- a/router.py +++ b/router.py @@ -284,9 +284,17 @@ def is_base64(image_string): def resize_image_if_needed(image_data): try: + # Check if already data-url + if image_data.startswith("data:"): + try: + header, image_data = image_data.split(",", 1) + except ValueError: + pass # Decode the base64 image data image_bytes = base64.b64decode(image_data) image = Image.open(io.BytesIO(image_bytes)) + if image.mode not in ("RGB", "L"): + image = image.convert("RGB") # Get current size width, height = image.size