HTML/CSS:来自原始图像数据而非url的背景图像 [英] HTML/CSS: Background Image from raw image data, not url
本文介绍了HTML/CSS:来自原始图像数据而非url的背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
使用数据URI :
document.getElementById('e').src = 'data:image/png;base64,ton_of_crap';
在该Wikipedia文章中,有用于PHP和Python的代码,它们输出基于64位编码的图像.您可以将其推入CSS文件的url()
(或<img />
标记的src
属性),它应该可以工作.
i get the raw image data of a png-image from a webserver, and want to use it as the background image of a div-element. is this possible without saving the data as an image-file first?
解决方案
Use a data URI:
document.getElementById('e').src = 'data:image/png;base64,ton_of_crap';
In that Wikipedia article, there is code for PHP and Python that outputs base-64 encoded images. You can just shove that into the url()
of a CSS file (or the src
attribute of a <img />
tag) and it should work.
这篇关于HTML/CSS:来自原始图像数据而非url的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文