Php5.2.2 and later versions of the GD library implement two screenshot functions: imagegrabscreen and imagegrabwindow, which are used to intercept the entire screen and capture the screen of a window (with ALT + printscreen.
1. Capture the whole screen screenshot
PHPCode
<? PHP
$ Im = imagegrabscreen ();
Imagepng ($ im, "myscreenshot.png ");
?>
2. capture a window (ie for example)
PHP code
<? PHP
$ Browser = new COM ("internetexplorer. application ");
$ Handle = $ browser-> hwnd;
$ Browser-> visible = true;
$ Im = imagegrabwindow ($ handle );
$ Browser-> quit ();
Imagepng ($ im, "iesnap.png ");
$ Im = imagegrabscreen ();
?>
3. Capture ie content capture a window (ie for example) but with its content!
PHP code
<? PHP
$ Browser = new COM ("internetexplorer. application ");
$ Handle = $ browser-> hwnd;
$ Browser-> visible = true;
$ Browser-> navigate ("http://kalvin.cn /");
/* Still working? */
While ($ browser-> busy ){
Com_message_pump (4000 );
}
$ Im = imagegrabwindow ($ handle, 0 );
$ Browser-> quit ();
Imagepng ($ im, "iesnap.png ");
?>
4. Intercept IE in fullscreen Mode
PHP code
$ browser = new COM ("internetexplorer. application ");
$ handle = $ browser-> hwnd;
$ browser-> visible = true;
$ browser-> fullscreen = true;
$ browser-> navigate ("http://kalvin.cn/");
/* Is it completely loaded? (Be aware of frames !) */
while ($ browser-> busy) {
com_message_pump (4000);
}< br> $ im = imagegrabwindow ($ handle, 0 );
$ browser-> quit ();
imagepng ($ im, "iesnap.png");
?>
The above explains how to use php com to call the IE window to open a webpage for screenshots, but many of my friends only get a pure black image. Why?
There may be two situations: the first case is that the COM component is only applicable to Windows servers, and the servers of other systems are not supported because it does not have Internet Explorer, the second case is that services are not allowed to interact with the desktop! In the second case, the most common method is to open a computer (my computer)-> right-click-> Manage-> services and applicationsProgram-> Service-> Apache (I use the Apache server myself)-> right-click-> properties-> login identity!