Php --- PHP uses the GD library to implement screenshots _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php --- PHP uses the GD library for screenshots. PHP uses the GD library to implement screenshot PHP5.2.2 and later versions. the GD library implements two screenshot functions: imagegrabscreen and imagegrabwindow, which are used to capture the entire screen and a window respectively (same as ALT + PHP using the GD library to achieve screenshot capture)
PHP5.2.2 and later versions of the GD Library implement two screenshot functions: imagegrabscreen and imagegrabwindow
It is used to intercept the entire screen and intercept a window (same as ALT + PrintScreen.
1. capture the whole 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 IE content 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. intercept IE in fullscreen 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 shoshould 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 didn't see the effect described in the manual, but a pure black image. why?
There may be two cases. The first case is that the COM component is only applicable to WINDOWS servers because it does not have an IE browser. The second case is that the service is not enabled to allow interaction with the desktop! The second case is the most common (disabled by default). how to enable it: click Computer (my computer) -> right-click-> Manage-> services and applications-> services-> Apache-> right-click-> Properties-> logon-> select to allow services to interact with the desktop.

In the second case, I installed the apache integration package, so that I could not find the apache service, so I was not successful in setting the second method. if there were any winners, hope to give you some advice.

From Zhang Dapeng

PHP5.2.2 and later versions of the GD Library implement two screenshot functions: imagegrabscreen and imagegrabwindow, which are used to intercept the entire screen and intercept a window respectively (same as ALT +...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.