Creating screenshots with PHP
Ever wondered how the site browser shots worked? I bet they're using a sort of custom COM object or PHP extension to create screenshots or maybe an other scripting language, but today I saw two nice PHP functions which can achieve the same result: imagegrabscreen(); and imagegrabwindow();.
They're added in PHP version 5.2.2, and only work on windows. I'm no windows user anymore, so I can't test it. To view an example, click 'Read more'
imagegrabwindow() example
- <?php
- // Start Internet Explorer
- $browser = new COM("InternetExplorer.Application");
- // Get the window handle
- $handle = $browser -> HWND;
- // Be sure the browser is visible
- $browser->Visible = true;
- // Navigate to a site
- $browser->Navigate("http://www.return1.net");
- // Still loading?
- while ($browser -> Busy)
- {
- com_message_pump(4000);
- }
- // Take a screenshot of the current window
- $im = imagegrabwindow($handle);
- // Quit the browser
- $browser->Quit();
- // And show the image
- imagepng($im);
imagegrabscreen() example

