Note that Python decodes base64 format image and saves it locally

Introduction

At work, I had to save the API that returns image data in base64 format locally. I struggled a little, so a memo (for beginners)

environment

python 3.7.0

base64 format

data:image/png;base64,iVBORw0KGg.....

code

splitString =Variable containing the base64 string.split(',')
    img_binary = base64.b64decode(splitString[1])
    filename='hoge.png'
    with open(filename, 'wb') as f:
        f.write(img_binary)

Recommended Posts

Note that Python decodes base64 format image and saves it locally
Note that it supports Python 3
A python program that resizes a video and turns it into an image
Note that I understand the least squares algorithm. And I wrote it in Python.
Image format in Python
A Python script that saves a clipboard (GTK) image to a file.
Python indentation and string format
Note that I understand the algorithm of the machine learning naive Bayes classifier. And I wrote it in Python.
This and that of python properties
Start the webcam to take a still image and save it locally
[python] Send the image captured from the webcam to the server and save it
Note that cibuildwheel builds python bwheel (including C ++ module) in bulk with CI and uploads it to PyPI