Skip to content

Instantly share code, notes, and snippets.

@squioc
Last active December 16, 2015 15:59
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 squioc/5460245 to your computer and use it in GitHub Desktop.
Save squioc/5460245 to your computer and use it in GitHub Desktop.
A python script to generate a base64 data-uri
#!/usr/bin/env python
import base64
import sys
import os
if len(sys.argv) != 3:
print "USAGE: %s <data-type> <file>" % sys.argv[0]
exit(1)
file = sys.argv[2]
if not os.path.exists(file):
print "ERROR: Please specify an existing file"
exit(2)
print "data:%s;base64,%s" % (sys.argv[1], base64.b64encode(open(sys.argv[2], "r").read()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment