data-url handling and removing alpha channel in images
This commit is contained in:
parent
ac25feadf8
commit
11f6e2dca6
1 changed files with 8 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue