tags:

views:

314

answers:

1

Hi, I am wanting to grab a screenshot using PHP and on my local Vista machine. For starters I just wanted to get the standard example set up:

$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.libgd.org");
/* Still working? */
while ($browser->Busy) {
    com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);

When I run the script (command line), it opens up two IE windows. One (the first) remains empty and the second goes to the designated URL. The screenshot is taken, saved and the first window gets closed. The window that went to the URL remains open. The screenshot itself taken from the first, empty IE window.

How can I target the second window?

-- EDIT #1 -- After all the help from Breakthrough it still does not work on my system. :( For now I am going to try to work it out with: http://iecapt.sourceforge.net/ or http://cutycapt.sourceforge.net/ which both seem to work during preliminary testing. I am still interested in a "real" PHP solution.

A: 

What version of IE are you using (7 or 8)?

What happens when you set the Visible property of $browser after navigating to the page?

-- EDIT IN RESPONSE TO COMMENT --

Go to Start -> Run, and type in "services.msc"

In the list, ensure that the Server Service and Remote Procedure Call (RPC) services are both set to automatic. Also, make sure that the Remote Procedure Call (RPC) Locator service is set to manual...

Try that and let us know what happens. :)

-- EDIT #2 --

In your php.ini file, make sure that com.allow_dcom is set to "1".

Breakthrough
IE: 7.0.6001.18000If I move the visible after the navigate only one browser window opens. No screenshot is made and I get an error (line-numbers edited to match top example): PHP Fatal error: Uncaught exception 'com_exception' with message 'Error [0x800706ba] The RPC-Server is not available.' in test.php:6Stack trace:#0 test.php(6): unknown()#1 {main} thrown in test.php on line 6
Casper
Go to Start -> Run, and type in "services.msc"In the list, ensure that the Server Service and Remote Procedure Call (RPC) services are both set to automatic. Also, make sure that the Remote Procedure Call (RPC) Locator service is set to manual...Try that and let us know what happens. :)
Breakthrough
My settings were already set to the way you described. No changes need to be made. Still getting the same errors.
Casper
In your php.ini file, make sure that com.allow_dcom is set to "1".
Breakthrough
Set it "not to 1"? Set the value to "1" - the default is 0 if it isn't set.
Breakthrough
It was commented out - set it now to 1, but I still get the same error. sorry - mistyped in previous comment. Also tried setting it to "True" - same result. In any case I still receive the error.
Casper