How to convert a base64 image in png format using python ?

Published: March 25, 2019

DMCA.com Protection Status

Example of how to convert a base64 image in png format using python (the input file base64.txt used in the following example can be found here):

import base64
from PIL import Image
from io import BytesIO

f = open('base64.txt', 'r')
data = f.read()
f.closed

im = Image.open(BytesIO(base64.b64decode(data)))
im.save('image.png', 'PNG')

returns:

How to save a base64 image in png format using python ?
How to save a base64 image in png format using python ?

References

Image

of