# Pass in a file where there's one base64 image per line
# This will write out a sequence of images, like image0001.png, image0002.png, ...

import fileinput
import base64

for index, line in enumerate(fileinput.input(), 1):
  if line.startswith('data:image/png;base64,'):
    with open('image{0:04}.png'.format(index), 'wb') as png:
       png.write(base64.b64decode(line.strip()[22:]))

# Save this into a file like decode.py
# Then run it with python3 decode.py input.txt

import os
os.system('ls -l')