如何在 Javascript 中从屏幕的某个区域创建图像?
我有一个网络应用程序,用户可以从一组用户界面组件中组装出一个用户界面(例如另一个网页),并且我想提供创建用户所创建内容的图像快照的选项。通过这种方式,我希望能够使用 JS(例如,使用 jQuery)以编程方式选择浏览器可显示区域的一个区域,并从该区域创建一个位图。
谢谢你!
I have a web app where a user can assemble a user interface (such as another webpage) out of some set of user interface components and I want to provide the option to create an image snapshot of what the user has created. In this way I want to be able to programmatically select, using JS (for example, using jQuery) a region of the browser's displayable area and create a bitmap from this region.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许这可以帮助您:http://html2canvas.hertzen.com/
Maybe this can help you: http://html2canvas.hertzen.com/
直接的 JavaScript,不太可能......但你没有提到你的整体“设置”,所以很难确定。执行您所描述内容的各个方面的工具。
PhantomJS - 带有 JavaScript API 的无头 WebKit。对 DOM 处理、CSS 选择器、JSON、Canvas 和 SVG 的本机支持。用于测试基于 Web 的应用程序、网站抓取、页面捕获、SVG 渲染器、PDF 转换器等。
Zombie.js - 使用 Node.js 进行“极其快速”的无头全栈测试。 Zombie.js 是一个轻量级框架,用于在模拟环境中测试客户端 JavaScript 代码。无需浏览器。
webkit2png - 是一个命令行工具,用于创建网页的 png 屏幕截图。
Straight JavaScript, unlikely.. But you don't mention your overall "setup", so it's hard to know for sure. Tools that perform aspects of what you are describing..
PhantomJS - headless WebKit with JavaScript API. Native support for DOM handling, CSS selector, JSON, Canvas, and SVG. For testing of web-based applications, site scraping, pages capture, SVG renderer, PDF converter, etc.
Zombie.js - "Insanely fast", headless full-stack testing using Node.js. Zombie.js is a lightweight framework for testing client-side JavaScript code in a simulated environment. No browser required.
webkit2png - is a command line tool that creates png screenshots of webpages.
我设法通过使用 HTML2Canvas 拍摄整个页面的快照并将画布裁剪为正确的大小来实现这一点。
I managed to make this happen with taking a snapshot of the whole page with HTML2Canvas and cropping canvas to the right size.
也许wkhtmltopdf会起作用,他们有一个似乎处于测试阶段的“to image”。然而,这需要的不仅仅是 JavaScript 才能完成,其他方法也是如此。
Maybe wkhtmltopdf would work, they have a 'to image' that appears to be in beta. This however requires more than just javascript to accomplish, as do other methods.