这应该使您朝正确的方向前进。
首先,假设您已检索到图像uri数据,并将其保存在名为img_data的python变量中:
# Exampleimg_data = 'data:image/jpeg;base64,/9j/4A...<lots of data>...k='
现在,您需要解码来自base64的图片并将其保存到文件中:
import base64# Separate the metadata from the image datahead, data = img_data.split(',', 1)# Get the file extension (gif, jpeg, png)file_ext = head.split(';')[0].split('/')[1]# Depre the image dataplain_data = base64.b64depre(data)# Write the image to a filewith open('image.' + file_ext, 'wb') as f: f.write(plain_data)


