Skip to content

Commit 5bfdd37

Browse files
committed
describe logic
Change-Id: I813e8569b91e01a0884b1c2ff75dfa84fcf4a609
1 parent d78d871 commit 5bfdd37

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

google/generativeai/types/content_types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@
7373

7474

7575
def pil_to_blob(img):
76+
# When you load an image with PIL you get a subclass of PIL.Image
77+
# The subclass knows what file type it was loaded from it has a `.format` class attribute
78+
# and the `get_format_mimetype` method. Convert these back to the same file type.
79+
#
80+
# The base image class doesn't know its file type, it just knows its mode.
81+
# RGBA converts to PNG easily, P[allet] converts to GIF, RGB to GIF.
82+
# But for anything else I'm not going to bother mapping it out (for now) let's just convert to RGB and send it.
83+
#
7684
# References:
7785
# - file formats: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html
7886
# - image modes: https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes

0 commit comments

Comments
 (0)