views:

26

answers:

0

I'm trying to screen cap different sites as I do some automated browsing to keep a reference image. I'm on a Windows 7 machine and using PHP 5.3.2 from the DOS prompt commandline to run a simple program to open a list of URLs in IE, capture the image, and quit.

It's the standard code...

$browser = new COM("InternetExplorer.Application");
$bhandle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate($url);
 while ($browser->Busy) {
 com_message_pump(4000);
}
$im = imagegrabwindow($bhandle,0);
$browser->Quit();
imagejpeg($im, "screencaps/" . $fname . ".jpg");
imagedestroy($im);

Sometimes I get a perfect capture. Sometimes it's a partial capture. Sometimes the interior window is black. It's sort of unpredictable. On two test runs I may get different results with the same URL.

I've tried other ways of detecting browser readiness, like...

 while (!($browser->ReadyState==4))

Still, not a perfect solution, though it seemed to work better. I've also tried fiddling with the second value in imagegrabwindow($bhandle), using 0, 1, and no value (since it's optional).

This isn't a blank image or black image like come up in so many Google searches. The rest of the IE window is always captured fine. It's just the interior web page portion of the IE window that blanks out partially or fully in a seemingly random manner. I haven't been able to figure out a rhyme or reason for why a page will capture perfectly on one run and blank out on another, or how to stop it.

Any help is appreciated.