<?php
//cong worked at Thu Jun 12 02:38:53 GMT 2008
/*
1.只能工作在windows下面,
2.web 服务器(iis或apache)做为windows服务时,必须打开”允许与桌面交互”的选项.(点击服务属性->登录->勾选”允许与桌面交互”,否则会出现黑屏
3.需要gb库版本为2.0.34(php5.2.2默认自带)
4.linux下可以使用khtml2png插件,网址:http://khtml2png.sourceforge.net/index.php?page=download
*/
set_time_limit(60);

//截屏
$im = imagegrabscreen();
imagepng($im, “snap1.png”);

//抓取IE窗口
$browser = new COM(“InternetExplorer.Application”);
$handle = $browser->HWND;
$browser->Visible = true;
$im = imagegrabwindow($handle);
$browser->Quit();
imagepng($im, “snap2.png”);
$im = imagegrabscreen();

//抓取IE窗口及窗口内容(IE为例)
$browser = new COM(“InternetExplorer.Application”);
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate(“http://www.chhua.com”);
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, “snap3.png”);

// IE全屏模式
$browser = new COM(“InternetExplorer.Application”);
$handle = $browser->HWND;
$browser->Visible = true;
$browser->FullScreen = true;
$browser->Navigate(“http://www.chhua.com”);
/* Is it completely loaded? (be aware of frames!)*/
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, “snap4.png”);

//生成网站缩略图
$browser = new COM(“InternetExplorer.Application”);
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Fullscreen = true;
$browser->Navigate(“http://www.chhua.com”);

while ($browser->Busy) {
com_message_pump(4000); //等待4秒
}

$im = imagegrabwindow($handle, 0); //抓取网页图像,需要php5.2.2以上版本的支持
$browser->Quit();

$new_img = imagecreatetruecolor(200,150);
imagecopyresampled($new_img,$im,0,0,0,0,200,150,1024,768);
imagejpeg($new_img , ‘snap5.jpg’,100);
imagedestroy($new_img);

echo “Done!”;

?>