1import base64
2image = open('deer.gif', 'rb')
3image_read = image.read()
4image_64_encode = base64.encodestring(image_read)
5image_64_decode = base64.decodestring(image_64_encode)
6image_result = open('deer_decode.gif', 'wb') # create a writable image and write the decoding result
7image_result.write(image_64_decode)
8