图片转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="">

相关文章:

  • 2021-12-21
  • 2021-09-14
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-11-23
  • 2021-09-03
猜你喜欢
  • 2022-03-01
  • 2021-06-25
  • 2021-05-29
  • 2021-09-13
  • 2022-12-23
  • 2021-08-15
  • 2021-06-27
相关资源
相似解决方案