使用(?)语言将元素的内容绘制到画布元素/捕获网站作为图像
我问了一个关于从 HTML 编译图像文件的问题。 Michaël Witrant 回复并告诉我有关 canvas 元素和 html5 的信息。
我在网上查看过,但是我没有找到任何有关将杂项元素的内容绘制到画布上的内容。这可能吗?
例如,假设我有一个带有背景图像的 div。有没有办法让这个元素及其背景图像“到”画布上?我问这个问题是因为我找到了一个脚本,允许将画布元素保存为 PNG,但我真正想做的是将 DOM 元素集合保存为图像。
编辑
无论什么语言,只要它能工作,我都愿意尝试。
I asked a question on SO about compiling an image file from HTML. Michaël Witrant responded and told me about the canvas element and html5.
I'm looked on the net and SO, but i haven't found anything regarding drawing a misc element's contents onto a canvas. Is this possible?
For example, say i have a div with a background image. Is there a way to get this element and it's background image 'onto' the canvas? I ask because i found a script that allows one to save the canvas element as a PNG, but what i really want to do is save a collection of DOM elements as an image.
EDIT
It doesn't matter what language, if it could work, i'm willing to attempt it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
郑重声明,
drawWindow
仅适用于 Firefox。该代码只能在本地运行,不能在互联网上运行,使用带有外部元素的drawWindow会产生安全异常。
在我们回答其他问题之前,您必须向我们提供更多背景信息。
For the record,
drawWindow
only works in Firefox.This code will only work locally and not on the internet, using drawWindow with an external element creates a security exception.
You'll have to provide us with a lot more context before we can answer anything else.
http://cutycapt.sourceforge.net/
CutyCapt 是一个命令行实用程序,使用 Webkit 将 HTML 渲染为 PNG 、PDF、SVG 等。您需要以某种方式与它交互(例如 PHP 中的 shell_exec),但它非常强大。站点的呈现方式与 Webkit 浏览器中的呈现方式完全相同。
我没有专门使用过 CutyCapt,但我强烈推荐它。我也使用过一款名为 WkHtmlToPdf 的类似产品,就我个人的体验而言,该产品非常棒。
http://cutycapt.sourceforge.net/
CutyCapt is a command line utility that uses Webkit to render HTML into PNG, PDF, SVG, etc. You would need to interface with it somehow (such as a shell_exec in PHP), but it is pretty robust. Sites render exactly as they do in Webkit browsers.
I've not used CutyCapt specifically, but it came to me highly recommended. And I have used a similar product called WkHtmlToPdf, which has been awesome in my personal experience.
经过多次尝试使用 drawWindow 参数绘制错误的部分或元素后,我设法通过两个步骤处理来完成此操作:首先在画布中捕获整个页面,然后在另一个画布中绘制该画布的一部分。
这是在 XUL 扩展中完成的。由于安全原因,drawWindow 无法在其他浏览器中工作,并且可能无法在非特权上下文中工作。
After many attempts using drawWindow parameters, that were drawing wrong parts or the element, I managed to do it with a two steps processing : first capture the whole page in a canvas, then draw a part of this canvas in another one.
This was done in a XUL extension. drawWindow will not work in other browsers, and may not work in a non-privileged context due to security reasons.