如何将 HTML 文档片段捕获为 alpha 透明的 PNG?
我正在寻找一种将网页的一部分捕获为透明背景 PNG 的方法。这意味着 transparent
背景属性将是真正透明的。根级元素不会显示白色,而是会创建具有透明背景的 png。
但是,我怀疑我正在寻找的行为是不可能的。我对这个问题的下一个猜测是创建一个画布元素,并以某种方式在画布上绘制一个 html 片段。从这里开始,捕获 PNG 就变得很简单了。
总结我的两个问题:
- 是否有一种相对简单的方法来捕获 HTML 文档片段作为 PNG,以便根节点
background:transparent
属性真正产生透明度? - 如果没有,我可以将 HTML 文档片段绘制到 canvas 元素吗?如果可以,我会得到想要的行为吗?
I'm looking for a way of capturing a section of a web page as a transparent-backgrounded PNG. This would mean that the transparent
background property would be truly transparent. A root level element, instead of displaying white, would create a png with a transparent background.
However, I suspect the behavior I'm looking for just isn't possible. My next guess at the problem would be to create a canvas element, and somehow draw a html fragment onto the canvas. From there, capturing a PNG is trivial.
To summarise my two questions:
- Is there a relatively simple way of capturing an HTML document fragment as a PNG, such that a root nodes
background: transparent
property truly results in transparency? - If not, can I draw an HTML document fragment to a canvas element, and if so, will I get the wanted behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Mozilla 在其 FF 4 beta 中有一个新的实验性功能,支持将实际的 HTML 元素渲染为背景另一个元素的。
Mozilla has a new experimental feature in its FF 4 beta that supports rendering an actual HTML element as a background of another element.
我不确定你到底想在#1 中捕捉什么。您想捕获用户所看到的图像吗?我认为那不可能。
对于 2,许多人都要求能够在 Canvas 上绘制 HTML 元素,但目前还没有 drawElement() 函数或类似的函数。 :(
您可以尝试通过大量绘图来模拟 Canvas 中的元素,但您肯定无法知道用户拥有哪种(比如说)主题。因此,如果用户具有 热狗摊 Windows 主题,无法相应地更改您的绘图。
I'm not sure precisely what you intend to capture in #1. Do you want to capture an image of what the user is seeing? I don't think thats possible.
For 2, the ability to draw HTML elements onto Canvas has been requested by various people but there is currently no drawElement() function or anything like it. :(
You can attempt to emulate the elements in Canvas with a ton of drawing, but you certainly cannot know what kind of (say) theme the user has. So if the user has the Hot-dog stand windows theme, there is no way to change your drawing accordingly.