【发布时间】:2017-12-20 17:41:17
【问题描述】:
import base64
from PIL import Image
def img_to_txt(img):
msg = ""
msg = msg + "<plain_txt_msg:img>"
with open(img, "rb") as imageFile:
msg = msg + str(base64.b64encode(imageFile.read()))
msg = msg + "<!plain_txt_msg>"
return msg
class decode:
def decode_img(msg):
img = msg[msg.find(
"<plain_txt_msg:img>"):msg.find(<!plain_txt_msg>")]
#how do I convert the str 'img', encoded in base64, to a PIL Image?
while 1:
decode.decode_img(img_to_txt(input()))
如何将字符串转换为 PIL Image 对象,我正在考虑将函数 frombytes() 与 PIL 的 Image 模块一起使用。
【问题讨论】:
标签: python-3.x character-encoding base64 python-imaging-library