最近我了解到我可以在网页中显示图像,而无需引用图像URL,如下所示:
<img class="disclosure" img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oIGRQbOY8MjgMAAABVSURBVBjTfc6xDcAwCETRM0rt5nbA+49j70DDAqSLsGXyJQqkVxxwNOeMiEA+waW1VuT/inrvG7wikht8UETy2ygVMjO4O8YYTf6AqrZyUwYlygAAXo+QLmeF4c4uAAAAAElFTkSuQmCC">
我有另一个我想要显示的小bmp图像,所以我在vim中打开它,img源代码就像:
当我将此代码粘贴到需要粘贴的地方时,我只能获得“BMڀ”
>如何正确转换/粘贴此代码以用作图像源?
解决方法@H_404_12@
您需要在Base64中对其进行编码
http://www.motobit.com/util/base64-decoder-encoder.asp
你还得改变(png)…
<img src="data:image/png;base64,
根据图像文件类型.
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,filesize($file));
return(base64_encode($binary));
}
echo '<img src="data:image/bmp;base64,'.encode64("test.bmp").'"/>';
测试了我的第二个功能……效果很好…… http://debconf11.com/so.php
http://www.motobit.com/util/base64-decoder-encoder.asp
你还得改变(png)…
<img src="data:image/png;base64,
根据图像文件类型.
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,filesize($file)); return(base64_encode($binary)); } echo '<img src="data:image/bmp;base64,'.encode64("test.bmp").'"/>';
测试了我的第二个功能……效果很好…… http://debconf11.com/so.php