base64 字符串转为图片(python代码)

将base64字符串转为图片的python代码,python为我们提供了b64decode函数,来实现这个功能。

import os
import base64   
import sys

strs = sys.argv[1] # 读取命令行中输入的参数,即base64字符串
img = base64.b64decode(strs) 

file = open('test.jpg','wb') 
file.write(img)  
file.close()

猜你喜欢

转载自blog.csdn.net/u010429424/article/details/79068833