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')
Python存储图片之编码解码
最新推荐文章于 2024-04-03 21:23:02 发布