Skip to content

Instantly share code, notes, and snippets.

@b1
Created September 14, 2011 11:06
Show Gist options
  • Save b1/1216322 to your computer and use it in GitHub Desktop.
Save b1/1216322 to your computer and use it in GitHub Desktop.
data uri image to base64
data_uri = open("sample.png", "rb").read().encode("base64").replace("\n", "")
img_tag = '<img alt="sample" src="data:image/png;base64,{0}">'.format(data_uri)
print img_tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment