如何制作 HTML 页面的屏幕截图(jpeg、png 等)?
我只想制作网站的屏幕截图,就像它在浏览器中呈现的那样,然后以编程方式将其保存为图像。假设我有一个网站,当我滚动链接时我想要一个预览功能。
根据我的研究,我发现我可以从命令行启动一个 Firefox 实例,并且有一些插件可以制作屏幕截图并返回它,而不是关闭该实例。
但是,为了做到这一点,我需要启动 xserver,但我不想这样做,因为从安全角度来看,这对我的服务器来说可能是危险的。
我的想法是在运行 xserver 和 firefox 的服务器上创建一个虚拟机,我的脚本连接到虚拟机,在那里启动 firefox 实例,获取图像并将其返回到浏览器。这应该是可能的,但似乎非常复杂。
所以我的问题是:您知道有其他替代方法可以以更简单/优雅的方式完成此任务吗?非常感谢您的意见。
I just want to make a screenshot of the website like it is rendered in the browser and save it as an image programaticaly. Let's say i have a website, and i want a preview function when i scroll over a link.
From my research i found that i can start a firefox instance from command line, and there is some plugin that can make the screenshot and return it, than shutting down the instance.
But, in order to do this i need to start the xserver and i don't want to do this as it's potencialy dangerous for my server from a security point of view.
My ideea is to create a virtual machine on the server running xserver with firefox, and my script to connect to the virtual machine, start the firefox instance there, get the image and return it to the browser. This should be possible but seems to be very complicated.
So my question is: Do you know any other alternative to accomplish this in a more simple/elegant way? Your opinions are highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我找到了一个很好的解决方案。我可以使用 CasperJS/PhantomJS (http://casperjs.org/) 或其他无头浏览器,所以我不需要 xserver 运行。感谢大家的支持!
Ok, I found a good solution. I can use CasperJS/PhantomJS (http://casperjs.org/) or other headless browser, so I don't need the xserver running. Thanks all for support !
Cutycapt 是您所需要的:
它已经打包在 Debian(自 Squeeze 起可用)和 Ubuntu 中。
Cutycapt is what you need:
It is already packaged in Debian (available since Squeeze) and Ubuntu.