1. 程式人生 > >python圖片轉為base64

python圖片轉為base64

int image port with open 解碼 import with 編碼 open

# -*- 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的編碼"/>

python圖片轉為base64