X2Painting / utils /data_convert.py
AntaresGuo's picture
Upload data_convert.py
cdd56aa verified
raw
history blame contribute delete
325 Bytes
import base64
from io import BytesIO
# pip3 install pillow
from PIL import Image
import re
def base64_to_image(base64_str):
base64_data = re.sub('^data:image/.+;base64,', '', base64_str)
byte_data = base64.b64decode(base64_data)
image_data = BytesIO(byte_data)
img = Image.open(image_data)
return img