Home > Backend Development > PHP Tutorial > php---PHP uses GD library to implement screenshot_PHP tutorial

php---PHP uses GD library to implement screenshot_PHP tutorial

WBOY
Release: 2016-07-13 17:49:59
Original
1149 people have browsed it

PHP uses GD library to realize screenshot
The GD library of PHP5.2.2 and above implements two screenshot functions imagegrabscreen and imagegrabwindow
Used to capture the entire screen and capture the screen of a certain window (same as ALT+PrintScreen) respectively.
1. Capture the entire screen Screenshot
$im = imagegrabscreen () ;
imagepng ( $im , " myscreenshot.png " ) ;
?>
2. Capture a window (IE for example)
$browser = new COM ( " InternetExplorer.Application " ) ;
$handle = $browser -> HWND ;
$browser -> Visible = true ;
$im = imagegrabwindow ( $handle ) ;
$browser -> Quit () ;
imagepng ( $im , " iesnap.png " ) ;
$im = imagegrabscreen () ;
?>
3. Capture a window (IE for example) but with its content!
$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. Capture IE in full screen mode
$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 " ) ;
?>
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

During the test, I did not get the effect mentioned in the manual, but a pure black picture. Why is this?
There may be two situations. The first situation is that this COM component is only applicable to the WINDOWS server because it does not have an IE browser; the second situation is that the service is not turned on to allow the service to interact with the desktop! The second case is the most common (closed by default). How to open it: click Computer (My Computer) -> Right-click -> Management -> Services and Applications -> Services -> Apache -> ; Right-click-> Properties-> Login-> Select Allow service to interact with desktop.

If it is the second case, I installed the apache integration package. In this case, I cannot find where the apache service is, so I did not succeed in setting up the second method. If anyone succeeds, I hope you can give me some advice. .

Excerpted from Zhang Dapeng

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478304.htmlTechArticlePHP uses the GD library to implement screenshots. The GD library of PHP 5.2.2 and above implements two screenshot functions, imagegrabscreen and imagegrabwindow respectively. Used to capture the entire screen and capture a window (same as ALT+...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template