# -*- coding: utf-8 -*-
import re
import base64
from cStringIO import StringIO
from PIL import Image
def base64_to_image(base64_str, image_path=None):
base64_data = re.sub('^data:image/.+;base64,', '', base64_str)
binary_data = base64.b64decode(base64_data)
img_data = StringIO(binary_data)
img = Image.open(img_data)
if image_path:
img.save(image_path)
return img
from:
https://www.jianshu.com/p/2ff8e6f98257
---------------------2020-10-22---------------------
postdata = base64.b64decode(postdata)
将数据保存为文件即可