How can I take a screenshot of a website with PHP and GD?

点点圈 提交于 2019-11-26 21:44:53

问题


How can I create a screenshot of a website using PHP and the GD library.


回答1:


While you might be able to do something with imagegrabscreen or imagegrabwindow you'd only be able to use it on a Windows box, and even then it would be tricky.

You'd have to open a browser window to the specified url (you could do that with exec) and grab a screenshot using the aforementioned methods.

Here's an example from the manual entry for imagegrabwindow:

<?php
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.libgd.org");

/* Still working? */
while ($browser->Busy) {
    com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);
?>



回答2:


Website is rendered on client side, while PHP and GD are server side. You may also check this website out. Hope it helps.



来源:https://stackoverflow.com/questions/627301/how-can-i-take-a-screenshot-of-a-website-with-php-and-gd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!