图片转base64字符串
import base64
with open("./logos.jpg", "rb") as fp:
data = base64.b64encode(fp.read())
print(str(data, encoding="utf-8"))
# imagedata = base64.b64decode(data)
with open("./test.txt", "wt") as f:
f.write(str(data, encoding="utf-8"))
# with open("./test.png", "wb") as f:
# f.write(imagedata)
# 网页中这么写,如果是png 对应 png
<img src="data:image/jpg; base64,base64字符串" alt="">