tags:

views:

1747

answers:

3

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

+3  A: 

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);
?>
Ross
Hi Ross,the code above gives following error/WarningPHP Warning: Module 'gd' already loaded in Unknown on line 0 PHP Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `InternetExplorer.Application': Access is denied. '
I'm having trouble even getting imagegrabscreen to work. As I said, I only copied that code from the manual. All I can suggest is that you follow the note on http://php.net/imagegrabscreen (assuming you're using Apache).
Ross
(Note that on Vista enabling Apache desktop support, restarting the service and the server still does not work)
Ross
A: 

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

Stiropor
A: 

You can use http://www.thumbshots.org/

vartec