Skip to content

Instantly share code, notes, and snippets.

@ryansturmer
Created August 1, 2012 15:27
Show Gist options
  • Save ryansturmer/3227806 to your computer and use it in GitHub Desktop.
Save ryansturmer/3227806 to your computer and use it in GitHub Desktop.
Convert Images to Base64 Encoded HTML
import base64
import os
def convert(infile):
with open(infile, 'rb') as fp:
data = fp.read()
b64 = base64.b64encode(data)
with open("%s.htm" % os.path.splitext(infile)[0], 'w') as fp:
fp.write('<html>\n\t<body>\n\t\t<img src="data:image/%s;base64,%s"/>\n</body>\n</html>' % (os.path.splitext(infile)[1], b64))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment