图片内联就是把图片数据放入到网页中,不再通过http去请求服务器获得图片(邮件中可以使用).
也有用做减少http请求: http://stevesouders.com/examples/inline-images.php
内联方式的格式: data:[<mediatype>][;base64],<data>
下面是Python 读取文件然后进行base64编码.
#-*- coding: utf-8 -*- import base64 def encode(i="", o=""): try: input = open(i, "rb") output = open(o, "wb") base64.encode(input, output) print "done..." except Exception, e: print e def decode(i="", o=""): try: input = open(i, "rb") output = open(o, "wb") base64.decode(input, output) print "done..." except Exception, e: print e if __name__ == "__main__": encode("1.gif", "1_base64.txt")
用上面代码把图片进行base64编码,把编码后的字符按标准放入<img src="https://img-blog.csdnimg.cn/2022010710543616122.gif" /> , 浏览可看到到图片.
在用Python 打开文件时得加入'b' 标志,开始没有加入测试,编码的文件不完整.
Firefox 和 Chrome 不仅支持图片, 而且还支持声音文字,更多参考: https://developer.mozilla.org/en/The_data_URL_scheme .
但是在ie8中测试不支持, 还有就是ie中对大小有限制.
参考文档: