Created
December 9, 2012 23:46
-
-
Save bkamapantula/4247543 to your computer and use it in GitHub Desktop.
Embed image in webpage using Python and CGI
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
# 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