将base64字符串解码为字节,并保存图片
def base64_to_images(base64_str, image_path):
"""
将base64字符串解码为字节,并保存图片
:param base64_str: base64字符串
:param image_path: 保存图片路径
:return:
"""
image_data = base64.b64decode(base64_str)
png = open(image_path, 'wb+')
png.write(image_data)
png.close()
将图片转成base64字节
def images_to_base64(image_path):
"""
将图片转成base64字节
:param image_path: 图片路径
:return:
"""
with open(image_path, 'rb') as f:
image_data = f.read()
base64_str = base64.b64encode(image_data)
print(base64_str)