I wrote this to go the other way (img to base64) for image URIs. I'm sure you could reverse this for what you need.
#!/usr/bin/env python
import sys
import os
import base64
if(__name__ == '__main__'):
arglen = len(sys.argv)
if arglen > 1:
imgfile = open(sys.argv[1], 'rb').read()
b64img = base64.b64encode(imgfile)
file_name = os.path.splitext(sys.argv[1])
fname = file_name[0]
fext = file_name[1]
b64imgfile = open(fname + fext + '.txt', 'w')
for line in b64img:
b64imgfile.write(line)
print fname
print fext
print('done')
else:
print('No img file specified!')
Update
*Here is some code that will reverse the above. The only caveat is that you need to know if it was png, jpg, etc. That should be in the data URI's of the images within the HTML page your pulling them from "img src='data:image/png;base64...". (I'm assuming png below)*
#!/usr/bin/env python
import sys
import os
import base64
if(__name__ == '__main__'):
arglen = len(sys.argv)
if arglen > 1:
b64file = open(sys.argv[1], 'rb').read()
imgData = base64.b64decode(b64file)
file_name = os.path.splitext(sys.argv[1])
fname = file_name[0]
fext = '.png'
imgFile = open(fname + fext, 'wb')
imgFile.write(imgData)
print('done')
else:
print('No file specified!')
Wow! This deserves more upvotes – Cesar Canassa – 2017-07-25T08:22:06.237
Correct ans. Such a sweet solution. – Bhumi Singhal – 2018-12-27T20:13:10.910