问题描述
< img 最近我了解到,我可以在网页中显示图片而无需引用图片网址。类= 公开 IMG SRC = 数据:图像/ PNG; BASE64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oIGRQbOY8MjgMAAABVSURBVBjTfc6xDcAwCETRM0rt5nbA + 49j70DDAqSLsGXyJQqkVxxwNOeMiEA + waW1VuT / inrvG7wikht8UETy2ygVMjO4O8YYTf6AqrZyUwYlygAAXo + QLmeF4c4uAAAAAElFTkSuQmCC >
我有另一个小的bmp图像,我想显示,所以我打开它在vim和img来源looke如:
当我把这段代码粘贴到需要粘贴的地方时,我只能得到BMڀ
- 如何正确地转换/粘贴此代码用作图像源? 您需要使用Base64编码 p>
另外,您必须在...中更改(png)...
< img src =data:image / png; base64,
根据图片文件类型。
这是一个小小的PHP函数,没有测试过。
函数encode64($ file){
$ extension = explode(。,$ fi le);
$ extension = end($ extension);
$ binary = fread(fopen($ file,r),filesize($ file));
$ b $ return'< img src =data:image /'.$ extension。'; base64,'。base64_encode($ binary)。'/>';
}
echo encode64(test.bmp); b
$ b $ 2 $ code> function encode64($ file){
$ binary = fread(fopen($ file,r),filesize($ file));
return(base64_encode($ binary));
}
echo'< img src =data:image / bmp; base64,'。encode64(test.bmp)。'/>';
测试过我的第二个功能...效果很好...
Recently i learned that i can display images in a web page without referencing an image URL as follows :
<img class="disclosure" img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oIGRQbOY8MjgMAAABVSURBVBjTfc6xDcAwCETRM0rt5nbA+49j70DDAqSLsGXyJQqkVxxwNOeMiEA+waW1VuT/inrvG7wikht8UETy2ygVMjO4O8YYTf6AqrZyUwYlygAAXo+QLmeF4c4uAAAAAElFTkSuQmCC">
I had another small bmp image that i wanted to display, so i opened it in vim and the img source looke like:
When i paste this code where it needs to be pasted i only get "BMڀ"
- How to i convert/paste this code properly to be used as an image source?
You need to encode it in Base64
http://www.motobit.com/util/base64-decoder-encoder.asp
Also you have to change (png) in...
according to image filetype.
Here is a little PHP function, haven't tested it.
function encode64($file){
$extension = explode(".", $file);
$extension = end($extension);
$binary = fread(fopen($file, "r"), filesize($file));
return '<img src="data:image/'.$extension.';base64,'.base64_encode($binary).'"/>';
}
echo encode64("test.bmp");
2.
function encode64($file){
$binary = fread(fopen($file, "r"), filesize($file));
return(base64_encode($binary));
}
echo '<img src="data:image/bmp;base64,'.encode64("test.bmp").'"/>';
Tested my second function... works great... http://debconf11.com/so.php
这篇关于在没有src URL的网页中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!