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.

Peshmerge.io-logo
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.