import base64
def encode_image(image_path, output_path):
with open(image_path, 'rb') as image_file:
image_data = image_file.read()
encoded_data = base64.b64encode(image_data)
with open(output_path, 'w') as output_file:
output_file.write(encoded_data.decode('utf-8'))
def decode_image(encoded_path, output_path):
with open(encoded_path, 'r') as encoded_file:
encoded_data = encoded_file.read()
image_data = base64.b64decode(encoded_data)
with open(output_path, 'wb') as output_file:
output_file.write(image_data)
# 编码图片
encode_image('dll/zp.jpg', 'encoded.txt')
# 解码图片
decode_image('encoded.txt', 'decoded.jpg')
09-27
3005
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-06
12-24
03-19
273
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)