

The function uses the mode as ‘wb’ (write binary). To write the data onto the file, we use the write() function in Python. We create a file named image.jpeg to store the decoded data in its original Image format.

This function takes the encoded data as a parameter. We decode the Base64 string data using the b64decode() function of the base64 module.We take the binary data and store it in a variable.In our case, the mode is ‘rb’ (read binary). The URL and Filename safe Base64 decoding is similar to the standard Base64 decoding except that it works with Base64’s URL and Filename safe Alphabet which uses hyphen (-) in place of + and underscore () in place of / character. The open() function takes two parameters-the file to be opened and the mode. We do this using the open() function in python. Then open the file which contains base64 string data for an image.
#Base64 decode python code#
The following steps give the working of the above code to convert the base64 string to Image in Python: How does the code to convert Base64 string to Image work? Output image generated after decoding the Base64 string: Input: Base64 string data stored in file1.txt: #write the decoded data back to original format in file Once the images have reached their destination, they can be decoded back to their original format.Ĭode to convert Base64 string to Image in Python #importing base64 moduleĭecoded_data=base64.b64decode((encoded_data))
#Base64 decode python how to#
In this tutorial, we will learn how to convert Base64 string to Image in Python. There is a need to convert them back to their original format. Such characters represent Base64 string data. Have you ever wondered how Images are being stored and transferred without being corrupted? Sometimes, when we open the images in their raw format, we observe that they are encoded in strange characters.
