Convert an image file to base64 string
(image_path)
| 5 | |
| 6 | |
| 7 | def image_to_base64(image_path): |
| 8 | """Convert an image file to base64 string""" |
| 9 | with open(image_path, "rb") as f: |
| 10 | image_data = f.read() |
| 11 | return base64.b64encode(image_data).decode("utf-8") |
| 12 | |
| 13 | |
| 14 | if __name__ == "__main__": |