Skip to content

Instantly share code, notes, and snippets.

@readingtype
Created August 21, 2013 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save readingtype/6296924 to your computer and use it in GitHub Desktop.
Save readingtype/6296924 to your computer and use it in GitHub Desktop.
Make a base64 encoded PNG in Python 2. The URI format for an img element's src attribute is data:image/png;base64 followed by a comma, followed by the content of the base64 encoded text file.
import base64
raw = open("path/to/image.png","rb")
encoded = open("path/to/image.png.base64.txt", "w")
encoded.write(base64.b64encode(raw.read()))
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment