Cogito ergo sum

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

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 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.

About the author

Peshmerge Morad

Data Science student and a software engineer whose interests span multiple fields.

Add comment

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

Cogito ergo sum