Skip to content

Instantly share code, notes, and snippets.

@felipebizz
Created April 9, 2015 22:43
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 felipebizz/8db172297140cde34695 to your computer and use it in GitHub Desktop.
Save felipebizz/8db172297140cde34695 to your computer and use it in GitHub Desktop.
Econde image for base64 in python
data_uri = open("/home/foto.png", "rb").read().encode("base64").replace("\n", "")
# HTML Image Element
img_tag = '<img alt="" src="data:image/png;base64,{0}">'.format(data_uri)
print img_tag
# CSS Background Image
css = 'background-image: url(data:image/png;base64,{0});'.format(data_uri)
print css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment