使用 Jquery 将 HTML 编译/保存/导出为 PNG 图像
我有一个包含多个变量的设置,用户可以更改该变量来影响元素的视觉表示。所有这些都是由 jquery 脚本控制的。如果有一种方法可以根据浏览器呈现的内容保存结果图像,那就太酷了。从用户角度来看,它与屏幕截图没有什么不同,尽管它只会捕获相关区域。
我有一个名为 Page Saver 的 FF 插件,它的功能几乎就是我想要的,但如果可能的话,可以使用 jquery 或常规 javascript。
我更多的是寻求提示,以及你们建议我去追求这样的功能的总体方向。我不想学习另一种语言来做到这一点,但如果我必须......
I have a set-up with multiple variables that users can alter that effect a visual representation of an element. All of this is controlled by jquery scripts. It would be cool if there was a way to save the resultant image as per what the browser renders. It'd be no different than a screencapture from a user perspective, though it would only capture the relevant area.
I have a plugin for FF called Page Saver, and it's functionality is pretty much what i am looking for, but with jquery or regular javascript if possible.
I'm more asking for tips, and a general direction that you guys would advise me to go in in order to pursue such functionality. I'd prefer not to learn another language to do this, but if i must...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:此方法仅适用于 Firefox 扩展。
您可以使用 HTML5 canvas、Firefox 的 drawWindow 和 toDataURL 方法。例如:
您可以调整
top
、left
、width
和height
以仅捕获网页的一部分。结果是一个 数据 URI 字符串。您可以将其发送到您的服务器或将其绘制在另一个画布上:
您的插件可能使用此方法。您还可以检查其源代码。
编辑:要使用 JQuery 将其发送到服务器,您可以执行以下操作:
在服务器端,您必须对数据 URL 进行解码。
Edit : This method only works in Firefox extensions.
You can use HTML5 canvas, Firefox' drawWindow and the toDataURL method. For example:
You can adjust
top
,left
,width
andheight
to capture only a part of the web page.The result is a data URI string. You can send it to your server or draw it on another canvas:
Your plugin probably uses this method. You can also check its source code.
Edit: To send it to your server with JQuery you can do something like that:
On the server side you'll have to decode the data URL.
遗憾的是,浏览器中没有内置 JS 功能,可以让您将图像转换为 HTML。因此,您需要安装一个浏览器插件或扩展程序,其中包含可以调用的 JS API。但即便如此,显然也需要在该人的浏览器上安装插件。
There is no JS functionality built into browsers that would allow you turn an image into HTML sadly. So you would need something like a browser plugin or extension installed that has a JS API that you can call into. But even then, it would obviously require that plugin be installed on that persons browser.