Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
Created December 9, 2012 23:46
Show Gist options
  • Save bkamapantula/4247543 to your computer and use it in GitHub Desktop.
Save bkamapantula/4247543 to your computer and use it in GitHub Desktop.
Embed image in webpage using Python and CGI
# http://stackoverflow.com/a/7389616/514874
data_uri = open('/path/to/image/image.png', 'rb').read().encode('base64').replace('\n', '')
img_tag = '<img src="data:image/png;base64,{0}" width="400" height="275">'.format(data_uri)
# I embedded .png image generated by Pyplot. Full credit to Glider@SO (http://stackoverflow.com/users/940789/glider) for making this work!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment