I have a string:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAAJbCAIAAABvnNkvAAAACXBIWXM и т.д.
Full:https://pastebin.com/tfDThBnE
How to convert to png and jpg and save this image in the file system?
I have a string:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAAJbCAIAAABvnNkvAAAACXBIWXM и т.д.
Full:https://pastebin.com/tfDThBnE
How to convert to png and jpg and save this image in the file system?
from PIL import Image
import base64
from io import BytesIO
data = 'copy_your_raw_data_here'
# you need to remove the prefix 'data:image/png;base64,'
bytes_decoded = base64.b64decode(data)
img = Image.open(BytesIO(bytes_decoded))
img.show()
# to jpg
out_jpg = img.convert("RGB")
# save file
out_jpg.save("saved_img.jpg")
if you don't have PIL(Pillow) library, make sure install it first.
pip install pillow
It is a python imgae handler package.