Skip to content

Instantly share code, notes, and snippets.

@snobu
Created June 3, 2024 13:14
Show Gist options
  • Save snobu/31fb185d193766bd83a7329e0cef085f to your computer and use it in GitHub Desktop.
Save snobu/31fb185d193766bd83a7329e0cef085f to your computer and use it in GitHub Desktop.
Image to base64
# Open the image file and encode it as a base64 string
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
base64_image = encode_image(IMAGE_PATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment