python图片转为base64

# -*- coding: utf-8 -*-    
import base64    
with open("/home/chaowei/1.png","rb") as f:  
# b64encode是编码,b64decode是解码  
base64_data = base64.b64encode(f.read())  
# base64.b64decode(base64data)  
print(base64_data)

前端

<img src="data:image/jpg;base64,这里是base64的编码"/>
posted @ 2019-04-04 11:35  公众号python学习开发  阅读(2430)  评论(0编辑  收藏  举报