data-url handling and removing alpha channel in images

This commit is contained in:
Alpha Nerd 2025-09-24 18:10:17 +02:00
parent ac25feadf8
commit 11f6e2dca6

View file

@ -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