Python 将base64字符串还原成图片保存&&图片转base64

base64转图片

import base64
def base64_to_img(bstr, file_path):
    imgdata = base64.b64decode(bstr)
    file = open(file_path, 'wb')
    file.write(imgdata)
    file.close()

 

图片转base64

import base64

f = open(img_path, 'rb')
img = base64.b64encode(f.read())

 

posted on 2021-05-26 16:12  星河赵  阅读(964)  评论(0编辑  收藏  举报

导航