誰說抓圖只能用QQ、用打印屏幕,PHP也能做到,本文主要介紹PHP抓屏函數實現屏幕快照的方法
代碼如下: <?php * 屏幕快照 $im = imagegrabscreen(); imagepng($im, "myscreenshot.png"); * 抓取一個窗口(IE為例) $browser = new COM("InternetExplorer.Application"); $handle = $browser->HWND; $browser->Visible = true; $im = imagegrabwindow($handle); $browser->Quit(); imagepng($im, "iesnap.png"); $im = imagegrabscreen(); // 抓取IE窗口及窗口內容(IE為例) $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全屏模式 $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"); ?> 需要說明幾點 1.這二種方法只能工作在windows下面, 2. 黑屏解決辦法--->>web 服務器(iis或apache)做為windows服務時,必須打開"允許與桌面交互"的選項.(點擊服務屬性->登錄->勾選"允許與桌面 交互".(一定要記得重起apache或其他的服務器才會有用,我已經成功,無庸質疑) 3.需要gb庫版本為2.0.34(php5.2.2默認自帶)