API: Properly handle Images with RGBA color format (#5332)
This commit is contained in:
parent
db1da9f98d
commit
166fdf09f3
1 changed files with 2 additions and 1 deletions
|
@ -156,8 +156,9 @@ def convert_history(history):
|
||||||
img = Image.open(BytesIO(my_res.content))
|
img = Image.open(BytesIO(my_res.content))
|
||||||
except Exception:
|
except Exception:
|
||||||
raise 'Image cannot be loaded from the URL!'
|
raise 'Image cannot be loaded from the URL!'
|
||||||
|
|
||||||
buffered = BytesIO()
|
buffered = BytesIO()
|
||||||
|
if img.mode in ("RGBA", "P"):
|
||||||
|
img = img.convert("RGB")
|
||||||
img.save(buffered, format="JPEG")
|
img.save(buffered, format="JPEG")
|
||||||
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
||||||
content = f'<img src="data:image/jpeg;base64,{img_str}">'
|
content = f'<img src="data:image/jpeg;base64,{img_str}">'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue