网站截图 [英] Website screenshots

查看:87
本文介绍了网站截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以用PHP拍摄网站的屏幕截图,然后将其保存到文件中?

解决方案

最后编辑:7年后,我仍然对此答案表示赞同,但我猜 HTMLTOPS ,呈现页面并将其输出到ps文件(ghostscript)中,然后将其转换为.jpg,.png,.pdf ..对于复杂的页面可能会稍微慢一些(并且不支持所有CSS).

否则,您可以使用 wkhtmltopdf 输出pdf,jpg等html页面. . 接受CSS2.0,使用Webkit(Safari的包装器)呈现页面. 您还必须将其安装在服务器上.

更新现在,借助新的HTML5和JS功能,还可以使用JavaScript将页面呈现到画布对象中.在这里,一个不错的库可以做到这一点: Html2Canvas 解决方案

LAST EDIT: after 7 years I'm still getting upvotes for this answer, but I guess this one is now much more accurate.


Sure you can, but you'll need to render the page with something. If you really want to only use php, I suggest you HTMLTOPS, which renders the page and outputs it in a ps file (ghostscript), then, convert it in a .jpg, .png, .pdf.. can be little slower with complex pages (and don't support all the CSS).

Else, you can use wkhtmltopdf to output a html page in pdf, jpg, whatever.. Accept CSS2.0, use the webkit (safari's wrapper) to render the page.. so should be fine. You have to install it on your server, as well..

UPDATE Now, with new HTML5 and JS feature, is also possible to render the page into a canvas object using JavaScript. Here a nice library to do that: Html2Canvas and here is an implementation by the same author to get a feedback like G+. Once you have rendered the dom into the canvas, you can then send to the server via ajax and save it as a jpg.

EDIT: You can use the imagemagick tool for transforming pdf to png. My version of wkhtmltopdf does not support images. E.g. convert html.pdf -append html.png.

EDIT: This small shell script gives a simple / but working usage example on linux with php5-cli and the tools mentioned above.

EDIT: i noticed now that the wkhtmltopdf team is working on another project: wkhtmltoimage, that gives you the jpg directly

这篇关于网站截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆