PHP imagegrabscreen and imagegrabwindow (screenshot website thumbnail) instance code

Source: Internet
Author: User

1. Capture the whole screen Screenshot
Copy codeThe Code is as follows:
<? Php
$ Im = imagegrabscreen ();
Imagepng ($ im, “myscreenshot.png ");
?>

2. Capture a window (IE for example)
Copy codeThe Code is as follows:
<? Php
$ Browser = new COM ("InternetExplorer. Application ");
$ Handle = $ browser-> HWND;
$ Browser-> Visible = true;
$ Im = imagegrabwindow ($ handle );
$ Browser-> Quit ();
Imagepng ($ im, “iesnap.png ");
$ Im = imagegrabscreen ();
?>

3. Capture the IE content Capture a window(IE for example) but with its content!
Copy codeThe Code is as follows:
<? Php
$ 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 ");
?>

4. Intercept the full screen mode of IEIE in fullscreen mode
Copy codeThe Code is as follows:
<? Php
$ Browser = new COM ("InternetExplorer. Application ");
$ Handle = $ browser-> HWND;

$ Browser-> Visible = true;
$ Browser-> FullScreen = true;
$ Browser-> Navigate (http://www.jb51.net ");

/* 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 ");
?>

The above explains how to use php com to call the IE window to open a webpage for screenshots, but many of my friends only get a pure black image. Why?
There may be two situations: the first case is that the COM component is only applicable to WINDOWS servers, and the servers of other systems are not supported because it does not have Internet Explorer, the second case is that services are not allowed to interact with the desktop! In the second case, the most common method is to open a computer (my computer) -> right-click-> Manage-> services and applications-> services-> Apache (I use the apache server myself) -> right-click and choose Properties> logon identity!

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.