php将image转换为base64编码
引用PHP手册里的一评论
This will greatly reduce your page load time as the browser will only need to send one server request for the entire page, rather than multiple requests for the HTML and the images. Requests need to be uploaded and 99% of the world are limited on their upload speed to the server.
翻译一下就是
这种方式能够大大减少页面载入时间,因为整个页面只需要一个请求,多个针对html文档和图片的请求。请求需要被提(上)交(传),但是99%的上传速度是被限制的。
所以减少请求也是一个明确的选择!
程序很简单,替换一下example.jpg为你的图片路径即可!
';
再来个python版本的
import base64
path = r'C:\Users\Administrator\Desktop\logo.png'
f = open(path,'rb')
b64 = base64.b64encode(f.read())
f.close()
print b64