简体   繁体   English

如何使用 PHP 获取网页的快照或缩略图?

[英]How might I obtain a Snapshot or Thumbnail of a web page using PHP?

I need to create Snapshots / Thumbshots / Site preview a-site.com.我需要创建快照/缩略图/站点预览 a-site.com。

There are some site as thumbshot.org that meets with I need.有一些网站如 thumbshot.org 可以满足我的需要。 But I do not want to use an external service, not to depend on others for my project (What would happen if they close the site?)但是我不想使用外部服务,也不想依赖其他人来做我的项目(如果他们关闭站点会发生什么?)

For this reason, I am looking for some project to let me do this.出于这个原因,我正在寻找一些项目让我这样做。

Any idea?有什么想法吗?

There isn't anything in the PHP library to do this - you're looking at setting up an external application (with a queue) to take images, although you can of course use PHP to add items to the queue. PHP 库中没有任何内容可以执行此操作 - 您正在考虑设置外部应用程序(带有队列)来拍摄图像,尽管您当然可以使用 PHP 将项目添加到队列中。

There are a couple of Windows functions in GD that takes screen shots of the computer (webserver - not the client) so perhaps you could write a script in PHP to do this. GD 中有几个 Windows 函数可以拍摄计算机(网络服务器 - 不是客户端)的屏幕截图,所以也许您可以用 PHP 编写一个脚本来执行此操作。

Edit: Was thinking of these:imagegrabscreen andimagegrabwindow .编辑:正在考虑这些:imagegrabscreenimagegrabwindow I'm not sure they will do what you want however (even in full screen mode Firefox has ablue bar at the top of the screen - not sure about other browsers).我不确定他们会做你想做的事(即使在全屏模式下,Firefox 在屏幕顶部也有一个蓝色的栏 - 不确定其他浏览器)。 However, Pierre has something on these functions if you're interested.但是,如果您有兴趣, 皮埃尔对这些功能有所了解。

I'd suggest writing an application in another language (I assume .NET has something) to do this for you.我建议用另一种语言编写一个应用程序(我假设 .NET 有一些东西)来为你做这件事。 Edit: This page tells you how to do it in C#编辑: 此页面告诉您如何在 C# 中执行此操作

On windows you can use GD's imagegrabwindow() function.在 Windows 上,您可以使用 GD 的imagegrabwindow()函数。

Edit: The help page actually shows you how to grab a screenshot from IE.编辑:帮助页面实际上向您展示了如何从 IE 抓取屏幕截图。

There's not much PHP would do for you in this situation.在这种情况下,PHP 不会为您做太多事情。 You'd need a complete (X)HTML rendering engine with CSS-support, possibly also with JavaScript support.您需要一个完整的 (X)HTML 渲染引擎,支持 CSS,可能还支持 JavaScript。

That, or use some kind of kinky script that would launch a real browser, and take a screenshot out of that.那,或者使用某种可以启动真正浏览器的古怪脚本,并从中截取屏幕截图。 Either way, PHP is probably not the right tool for the operational part.无论哪种方式,PHP 可能都不是用于操作部分的正确工具。

There's a Firefox extension that converts the webpage you're viewing to an image:有一个 Firefox 扩展程序可以将您正在查看的网页转换为图像:

http://www.screengrab.org/ http://www.screengrab.org/

http://addons.mozilla.org/en-US/firefox/addon/1146 http://addons.mozilla.org/en-US/firefox/addon/1146

If you're willing to get creative, it might be possible to access this problematically.如果您愿意发挥创造力,则可能会遇到问题。

Thanks to all.谢谢大家。 I found a pseudo-solution, (using dcom + imagegrabscreen + wamp).我找到了一个伪解决方案,(使用 dcom + imagegrabscreen + wamp)。 I need to resize the final.png with gd, because the png is equal to resolution of client (in my home, is a picture of 1650*1280).我需要用gd调整final.png的大小,因为png等于客户端的分辨率(在我家,是1650 * 1280的图片)。 Whe I end this, I will post a .zip file to dowload Thanks again (But if anyone have a better idea, I am happy to see that)当我结束这个时,我会发布一个 .zip 文件来下载再次感谢(但如果有人有更好的主意,我很高兴看到)

PS: Sorry for my english PS:对不起我的英语

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

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