Created
August 1, 2012 15:27
-
-
Save ryansturmer/3227806 to your computer and use it in GitHub Desktop.
Convert Images to Base64 Encoded HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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