Last active
December 6, 2021 05:53
-
-
Save ankitshekhawat/56f05d0fb0453a0cd143630ab5af5087 to your computer and use it in GitHub Desktop.
Convert PIL image to DataURI
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
#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