How to save a base64 encoded image on hard disk in Python1 min read

In

,

In some cases you receive an image as bas64 encoded string and you need to save it first on disk before you can reopen it and use it!

First of all, you have to import the base64 package.

import base64
decoded_image= base64.b64decode(YOUR_BASE64_ENCODED_IMAGE)
with open('your_image.jpg', 'wb') as f:
    f.write(decoded_image)

YOUR_BASE64_ENCODED_IMAGE is the base64 encoded string of the image.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.