Created
May 7, 2014 10:41
-
-
Save skvggor/1da5b034fced240a84ba to your computer and use it in GitHub Desktop.
Convert PNG to data uri/base64
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
#!/usr/bin/python | |
# encoding: utf-8 | |
import urllib | |
def convert_png_to_datauri(image_file): | |
image_encoded = urllib.quote(open(image_file, 'rb').read().encode('base64')) | |
return 'data:image/png;base64,' + image_encoded | |
if __name__ == '__main__': | |
print convert_png_to_datauri('/home/xxx/Copy/Photos/tecmundo.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment