Skip to content

Instantly share code, notes, and snippets.

@olooney
Created February 14, 2012 22:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save olooney/1831221 to your computer and use it in GitHub Desktop.
Save olooney/1831221 to your computer and use it in GitHub Desktop.
simple python script to generate an inline data: URL for a jpeg image from a file
def make_data_url(filename):
prefix = 'data:image/jpeg;base64,'
fin = open(filename, 'rb')
contents = fin.read()
import base64
data_url = prefix + base64.b64encode(contents)
fin.close()
return data_url
@happyman
Copy link

data_url = prefix + base64.b64encode(contents).decode("utf-8")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment