2016-05-30 130 views
0

我目前正在制作一个网站,我只希望用户能够截图网页,然后下载图像。所以我需要帮助的是:我如何使用PHP截图网页然后将图像保存在我的服务器上。如何在php中截图网页?

我已经阅读了一些关于如何截图页面的其他教程,但我无法让它工作。

我正在使用Linux服务器(Debian 7.0)。

+2

您可以包括到目前为止你已经走了代码,请。 –

回答

1

您可以使用grabz.it


采取截图的网站使用PHP

  1. 获取免费Application Key and Secret
  2. 下载免费的PHP Demo and Library并尝试一下。

然后使用它是这样的:

include("GrabzItClient.class.php"); 
$grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET"); 
$grabzIt->SetImageOptions("http://www.google.com"); 
$grabzIt->SaveTo("google.jpg"); 

如果你不想依赖于第三方,您可以使用phantomjs,即:

phantomjs responsive-screenshot.js http://google.com 

备注:

1- Download responsive-screenshot.js。检查可用选项的源代码。

2 - 您可以通过克隆GitHub库安装phantomjs:

git clone https://github.com/ariya/phantomjs.git 
+0

谢谢你!这完美的作品:D –

+0

非常欢迎你@AntonKihlström –

0

我最近出版的一期工程,让到浏览器PHP访问。在这里获取:https://github.com/merlinthemagic/MTS

像以前的答案这个项目依赖PhantomJS。

下载和安装您只需使用下面的代码后:

$myUrl   = "http://www.google.com"; 
$windowObj  = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($myUrl); 

//now do a screenshot, valid formats are png, jpeg, gif. 
$imageData  = $windowObj->screenshot("png"); 

file_put_contents("/path/to/your/file.png", $imageData);