Skip to content

Instantly share code, notes, and snippets.

@Menziess
Last active December 25, 2017 23:22
Show Gist options
  • Save Menziess/2a24cd014062223febc98708de39c1f0 to your computer and use it in GitHub Desktop.
Save Menziess/2a24cd014062223febc98708de39c1f0 to your computer and use it in GitHub Desktop.
Python base64 encoding decoding
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