Skip to content

Instantly share code, notes, and snippets.

@1c7
Last active August 27, 2018 10:59
Show Gist options
  • Save 1c7/64eb0372840cbf5cf3bfb1e007cef651 to your computer and use it in GitHub Desktop.
Save 1c7/64eb0372840cbf5cf3bfb1e007cef651 to your computer and use it in GitHub Desktop.
HTML <img src="data:image/jpeg;base64"> to Image file using Python 3
# Python 3
import base64
# Fill in this
base64_string = 'data:image/jpeg;base64, ...etc..'
array = url.split('data:image/jpeg;base64,')
base64_naked = array[1]
imgdata = base64.b64decode(base64_naked)
with open('haha.jpg', 'wb') as f:
f.write(imgdata)
@1c7
Copy link
Author

1c7 commented Aug 27, 2018

What this code does

This code snippet help you turn <img src='data:image/jpeg;base64, ...etc..'>
into Image file.

all you have to do is fill in base64_string variable

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