平时多见的<img>的使用,常见于如下:
<img class="img-responsive img-rounded" src="static/img/user.jpg" alt="">
但是如果src地址不便给出,可以给出如下:
<img class="img-responsive img-rounded" src="data:image/png;base64, /9j/2wCEAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDIBCQkJDAsMGA0NGDIhHCEyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMv/AABEIALQAtAMBIgACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+gEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APf6KKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKYzKqksQABkk9qAH1l6prWn6LHG9/dLE0rbIowC0kreiqoLMfYA1kf2vf8AiBjFoDCCyOQ+rSR7gSDgiFDjeevzn5RjgNyBpaXoFjpcss8aPJeT4M13OxeWU+7H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Y6hem7xs2+WPLjjC9TniPOeOvSovCuh/wDCM+GbHRvtJuRaqUEpTaWBYkcZOOuOvagDjrlNVOoS7ykfi7XIhDCkf7waRYA8szA4LAknOcNIVAyFzXX6Xf6dbeF0vINQmvNPtYGLXTu07uI8hix5ZmypyMZzwB2rGtvhvp1tqd5qH9seIWnvJN8xXU5I92OFBKbSQo4AJOBwK1dB8K2fhy/1CfT7i7FvessslvNO0qibndJuclizAqDk/wAI9sAHmF9dzJ4i8Pvp016ctcGNdI8OmyYZQcqLkFH46kngZPHFd7Lc6vL4S1e2mstfiuRaOsF1KLZ7p3cMAY1t3CgpkEZKk+uQTWvrvh7+2brT7uPULuwu7FnaGa2WNjh12sCJFYHj2qLR/DR0q61C+fV7++v79Y0kuLjywUCBgoRVQKo+Ynocnk5oA8un8Q3+m6TqjWJ1a3u1N/eLDEtm0cTNeTxoJA6szHeApEbEHtnrXe+CdUfULzUYnn1KUxxwSqbxrRlZJAxVka3UAggdye2Mc5XSvh9p2nX9hPJLJcrY2kcMay5+aVXdzM2DhiWkJwQQDg9QMaWieGIdF1TVryCUlb+RWWIQpGkKruIUBQM5Z3JJ5OeeeSAdJRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAwsc0m40HrSUAf/2Q==" alt="">
两个效果一样
可以直接将src中字符串拷贝到地址栏中 就可以看到图片
转载如下:http://blog.csdn.net/qq_18979049/article/details/78610502?locationNum=10&fps=1
这是Data URI scheme。
Data URI scheme是在RFC2397中定义的,目的是将一些小的数据,直接嵌入到网页中,从而不用再从外部文件载入。比如上面那串字符,其实是一张小图片,将这些字符复制黏贴到火狐的地址栏中并转到,就能看到它了,一张1X36的白灰png图片。
在上面的Data URI中,data表示取得数据的协定名称,image/png 是数据类型名称,base64 是数据的编码方法,逗号后面就是这个image/png文件base64编码后的数据。
目前,Data URI scheme支持的类型有:
data:,文本数据
data:text/plain,文本数据
data:text/html,HTML代码
data:text/html;base64,base64编码的HTML代码
data:text/css,CSS代码
data:text/css;base64,base64编码的CSS代码
data:text/javascript,Javascript代码
data:text/javascript;base64,base64编码的Javascript代码
data:image/gif;base64,base64编码的gif图片数据
data:image/png;base64,base64编码的png图片数据
data:image/jpeg;base64,base64编码的jpeg图片数据
data:image/x-icon;base64,base64编码的icon图片数据
base64简单地说,它把一些 8-bit 数据翻译成标准 ASCII 字符,网上有很多免费的base64 编码和解码的工具,在PHP中可以用函数base64_encode() 进行编码,如echo base64_encode(file_get_contents(‘wg.png’));
目前,IE8、Firfox、Chrome、Opera浏览器都支持这种小文件嵌入。
举个图片的例子:
网页中一张图片可以这样显示:
<img src=“http://www.letuknowit.com/images/wg.png”/>
也可以这样显示:
<img src=“data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAkCAYAAABIdFAMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHhJREFUeNo8zjsOxCAMBFB/KEAUFFR0Cbng3nQPw68ArZdAlOZppPFIBhH5EAB8b+Tlt9MYQ6i1BuqFaq1CKSVcxZ2Acs6406KUgpt5/LCKuVgz5BDCSb13ZO99ZOdcZGvt4mJjzMVKqcha68iIePB86GAiOv8CDADlIUQBs7MD3wAAAABJRU5ErkJggg%3D%3D”/>
我们把图像文件的内容直接写在了HTML 文件中,这样做的好处是,节省了一个HTTP 请求。坏处呢,就是浏览器不会缓存这种图像。大家可以根据实际情况进行自由取舍。
来源:oschina
链接:https://my.oschina.net/u/4411583/blog/4228568