Home > Article > Backend Development > PHP screen capture function implements screen snapshot code sharing_PHP tutorial
* Capture a window (IE as an example)
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$im = imagegrabwindow($ handle);
$browser->Quit();
imagepng($im, "iesnap.png");
$im = imagegrabscreen();
// Capture IE window and window content (IE as an example)
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate ("http://www.jb51.net");
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
//IE full screen mode
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->FullScreen = true;
$browser->Navigate("http://www.jb51.nett");
/* Is it completely loaded? (be aware of frames!)*/
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
?>
A few points need to be explained
1. These two methods can only work under windows,
2. Black screen solution--->>When the web server (iis or apache) is used as a windows service , the option "Allow interaction with desktop" must be turned on. (Click service properties->Login->Check "Allow interaction with desktop". (Be sure to remember to restart apache or other servers to make it useful. I have succeeded. , no doubt)
3. The required gb library version is 2.0.34 (php5.2.2 comes with it by default)