Andy's Blog » php 截屏, php截屏, php InternetExplorer Application, wkhtmltoimage使用, php截屏函数, php gd截屏 纯黑, phpgdp, gd2 截屏, php 截取屏幕, php 截屏固定位置 函数, ibrowser2 » PHP使用GD库实现截屏

PHP使用GD库实现截屏

PHP使用GD库实现截屏

PHP5.2.2以上版本的GD库实现了两个截屏函数 imagegrabscreenimagegrabwindow
分别用于截取整个屏幕和截取某个窗口(同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/new/");
 
/* 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/new/");
 
/* 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");
?>

I use Internet Example Explorer as example, if you like to play more with IE and com, check out the IBrowser2 documentation at MSDN. It should work with any kind of window as long as you give the correct handle (usually $obj->HWND).

* php_gd2.dll for 5.2.x thread safe build
* php gd image documentation
* IE manual (useful to tweak it from com_dotnet

Incoming search terms:

Tags: PHP, 截屏

本文地址: http://www.21andy.com/new/20071122/684.html

1 评论 to “PHP开源CMS之MODx”

  1. 王道中强流 于 2011-03-25 15:52:05 发表:

    不是5.2.2怎么截全屏?