简体   繁体   English

如何使用PHP将网页保存为图像文件?

[英]How to save webpage as a image file using PHP?

I want to save webpage as image file or i want to take snapshot of an webpage using PHP. 我想将网页保存为图像文件,或者我想使用PHP拍摄网页的快照。 Just like firefox extension Fireshot doing. 就像firefox扩展Fireshot一样。

You'll need to render the page with something. 您需要使用某些内容呈现页面。 If you really want to only use php, i suggest you HTMLTOPS , wich render the page and output it in a ps file (ghostscript), then, convert it in a .jpg, .png, .pdf.. can be little slower with complex pages (and dont support all the CSS). 如果你真的只想使用php,我建议你使用HTMLTOPS ,它会渲染页面并将其输出为ps文件(ghostscript),然后将它转换为.jpg,.png,.pdf ..可能会慢一些复杂的页面(并且不支持所有的CSS)。

Else, you can use wkhtmltopdf to output a html page in pdf, jpg, whaterver.. Accept CSS2.0, use the webkit (safari's wrapper) to render the page.. so should be fine. 否则,您可以使用wkhtmltopdf以pdf,jpg,whaterver输出html页面。接受CSS2.0,使用webkit(safari的包装器)来呈现页面..所以应该没问题。 You have to install it on your server, as well.. 你必须在你的服务器上安装它。

Source: Website screenshots using PHP 来源: 使用PHP的网站截图

Like others have said, it would be difficult to do in PHP alone. 就像其他人所说的那样,单靠PHP就很难做到。 However, there is an easy-to-use cross-platform tool called CutyCapt that does exactly what you need. 但是,有一个名为CutyCapt的易于使用的跨平台工具可以完全满足您的需求。 The best part about this tool is that it's stand-alone and doesn't depend on anything else. 关于这个工具最好的部分是它是独立的,不依赖于任何其他东西。

你不能用纯PHP做到这一点,尝试用无头模式分配像Mozilla这样的浏览器,让它处理页面的快照。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM