Skip to content

Instantly share code, notes, and snippets.

@ankitshekhawat
Last active December 6, 2021 05:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitshekhawat/56f05d0fb0453a0cd143630ab5af5087 to your computer and use it in GitHub Desktop.
Save ankitshekhawat/56f05d0fb0453a0cd143630ab5af5087 to your computer and use it in GitHub Desktop.
Convert PIL image to DataURI
#python3
def pil2datauri(img):
#converts PIL image to datauri
data = BytesIO()
img.save(data, "JPEG")
data64 = base64.b64encode(data.getvalue())
return u'data:img/jpeg;base64,'+data64.decode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment