We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7342a62 commit 5e56b4fCopy full SHA for 5e56b4f
google/generativeai/types/content_types.py
@@ -74,10 +74,18 @@
74
75
def pil_to_blob(img):
76
bytesio = io.BytesIO()
77
- if isinstance(img, PIL.PngImagePlugin.PngImageFile) or img.mode == "RGBA":
+
78
+ get_mime = getattr(img, "get_format_mimetype", None)
79
+ if get_mime is not None:
80
+ # If the image is created from a file, convert back to the same file type.
81
+ img.save(bytesio, format=img.format)
82
+ mime_type = img.get_format_mimetype()
83
+ elif img.mode == "RGBA":
84
img.save(bytesio, format="PNG")
85
mime_type = "image/png"
86
else:
87
+ if img.mode != "RGB":
88
+ img = img.convert('RGB')
89
img.save(bytesio, format="JPEG")
90
mime_type = "image/jpeg"
91
bytesio.seek(0)
0 commit comments