0
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圖像對象,我正在考慮使用來自Piles的Image模塊的Bytes()函數。如何將base64字符串轉換爲PIL圖像對象