import base64
imgPath = 'img.jpg'
def encode(img):
with open(img, 'rb') as f:
imageData = f.read()
base64Data = base64.b64encode(image_data)
print(base64Data) # b'***'
return base64Data
def decode(code, name):
with open(name, 'wb') as file:
jiema = base64.b64decode(code)
file.write(jiema)
ss = encode(imgPath)
print(ss)
with open("code.txt", "w") as f:
f.write(str(ss))
decode(ss, 'decode.jpg')
对图片进行base64编解码
最新推荐文章于 2024-09-10 10:57:07 发布