Base64 encoding is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It is commonly used to encode non-textual data such as images, audio, and binary files.
To convert a base64-encoded string to an image and save it to the filesystem, you can use the following steps:
Here is an example of how to perform these steps in Python:
import base64 # Decode the base64-encoded string decoded_data = base64.b64decode(base64_string) # Create a new file with open('image.png', 'wb') as f: # Write the decoded binary data to the file f.write(decoded_data)
In this example, base64_string is the base64-encoded string, and image.png is the name of the file to be created.
Once the file is saved, you can verify that the image has been correctly decoded by opening it in an image viewer.
The above is the detailed content of How to Convert Base64 Encoded String to Image and Save to File?. For more information, please follow other related articles on the PHP Chinese website!