Spaces:
Build error
Build error
Ilia Tambovtsev commited on
Commit ·
4878bbb
1
Parent(s): 4f24845
feat: add function to convert pil image to base64
Browse files
src/pdf_utils/image_utlis.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import base64
|
| 3 |
+
import io
|
| 4 |
+
|
| 5 |
+
def pil_image_to_base64(pil_image: Image):
|
| 6 |
+
buffered = io.BytesIO()
|
| 7 |
+
pil_image.save(buffered, format="png")
|
| 8 |
+
img_str = base64.b64encode(buffered.getvalue())
|
| 9 |
+
return img_str.decode("utf-8")
|