Last active
December 25, 2017 23:22
-
-
Save Menziess/2a24cd014062223febc98708de39c1f0 to your computer and use it in GitHub Desktop.
Python base64 encoding decoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
path = "image_path.png" | |
encoded_path = "encoded.txt" | |
decoded_path = "image_restored.png" | |
with open(path, 'rb') as file: | |
data = base64.encodestring(file.read()) | |
with open(encoded_path, "wb") as txt: | |
txt.write(data) | |
with open(encoded_path, 'rb') as file: | |
data = base64.decodestring(file.read()) | |
with open(decoded_path, "wb") as img: | |
img.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment