import base64

if __name__ == "__main__":
    dir='image.jpg'
basef=open(dir.split('.')[0]+'_base64.txt','w') with open (dir,'rb') as f: base64_data=base64.b64encode(f.read()) s=base64_data.decode() data='data:image/jpeg;base64,%s'%s # print(data) basef.write(data) basef.close()

最后,会在当前目录下生成对应的base64.txt文件,同理,解码用

base64.b64decode()

相关文章:

  • 2022-01-10
  • 2021-11-19
  • 2022-12-23
  • 2021-07-06
  • 2022-01-24
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2021-10-22
  • 2022-12-23
  • 2021-08-12
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案