Contents

[Python]圖片轉成base64碼

Contents

實作異常的順力^^

1
2
3
4
5
6
7
import base64

fp = open("a.jpg","rb")
img = fp.read()
fp.close()

print(base64.b64encode(img))

在接下來使用requests來實作

1
2
	imgdata = requests.get(imgurl).content
	imgb64 = base64.b64encode(imgdata)

完成:D