PHP5.2.2以上版本的GD库实现了两个截屏函数 imagegrabscreen 和 imagegrabwindow分别用于截取整个屏幕和截取某个窗口(同ALT+PrintScreen)的屏幕。
1. 截取整个屏幕 Screenshot- <?php
- $im = imagegrabscreen();
- imagepng($im, "myscreenshot.png");
- ?>
复制代码 2. 截取一个窗口 Capture a window (IE for example)- <?php
- $browser = new COM("InternetExplorer.Application");
- $handle = $browser->HWND;
- $browser->Visible = true;
- $im = imagegrabwindow($handle);
- $browser->Quit();
- imagepng($im, "iesnap.png");
- $im = imagegrabscreen();
- ?>
复制代码 3. 截取IE内容 Capture a window (IE for example) but with its content!- <?php
- $browser = new COM("InternetExplorer.Application");
- $handle = $browser->HWND;
- $browser->Visible = true;
- $browser->Navigate("http://www.21andy.com/blog/");
-
- /* Still working? */
- while ($browser->Busy) {
- com_message_pump(4000);
- }
- $im = imagegrabwindow($handle, 0);
- $browser->Quit();
- imagepng($im, "iesnap.png");
- ?>
复制代码 4. 截取IE的全屏模式 IE in fullscreen mode- <?php
- $browser = new COM("InternetExplorer.Application");
- $handle = $browser->HWND;
-
- $browser->Visible = true;
- $browser->FullScreen = true;
- $browser->Navigate("http://www.21andy.com/blog/");
-
- /* 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");
- ?>
复制代码 几个要注意的问题:
1.这2个函数只能工作在是windows上的服务器运行,不难看出,例子大部分都是用了ie来截图的;
2. 需要php版本PHP 5 >= 5.2.2,gb库版本>=2.0.34;
3.web 服务器(iis或apache)做为windows服务时,必须打开”允许与桌面交互”的选项.(点击服务属性->登录->勾选”允许与桌面交互”。 |