Page 1 of 1

php code doesn't work: a screen print program, who help ?

Posted: Thu Sep 25, 2008 9:58 pm
by linphp
I need to print screen via php, below is the code I got through google, but it doesn't work, and I can't find out what wrong.

Code: Select all

 
<?php
//Screenshot
$im = imagegrabscreen();
imagejpeg($im, "myscreenshot.jpg");
 
//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();
 
//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.baidu.com");
 
// Still working?
while ($browser->Busy) {
    com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
 
//set IE in fullscreen mode
 
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->FullScreen = true;
$browser->Navigate("http://www.google.com");
 
// 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");
?>
 
 

Re: php code doesn't work: a screen print program, who help ?

Posted: Thu Sep 25, 2008 10:56 pm
by linphp
guys help

Re: php code doesn't work: a screen print program, who help ?

Posted: Fri Sep 26, 2008 2:53 am
by onion2k
What have you done to try and work out what the problem is?

Re: php code doesn't work: a screen print program, who help ?

Posted: Fri Sep 26, 2008 10:23 am
by linphp
I tried to run the code, but I got the following error info:
Warning: imagegrabwindow() [function.imagegrabwindow]: gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully in D:\Program Files\Easy2PHP5\WebSite\test2.php on line 10

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Unknown<br/><b>Description:</b> Unknown' in D:\Program Files\Easy2PHP5\WebSite\test2.php:11 Stack trace: #0 D:\Program Files\Easy2PHP5\WebSite\test2.php(11): com->Quit() #1 {main} thrown in D:\Program Files\Easy2PHP5\WebSite\test2.php on line 11

Re: php code doesn't work: a screen print program, who help ?

Posted: Fri Sep 26, 2008 10:27 am
by onion2k
Looks like the imagegrabwindow() function is broken. It's only very experimental code, and it does tend to be very dependent on the specific build of PHP. I've never managed to get it working... I suggest you install a newer version of PHP, or build it yourself from the source of a version where that function is definitely working.

Re: php code doesn't work: a screen print program, who help ?

Posted: Fri Sep 26, 2008 11:27 am
by linphp
thanks onion2k.

I check the function "imagegrabwindow" in php manual, it tells me that imagegrabwindow() requires php5.2.2 + , and my php version is php5.2.5, function_exists("imagegrabwindow") returns true. but the code didn't work. Then I download php5.2.6, function_exists("imagegrabwindow") returns true, but still doesn't the code work and causes the same the error.


Is it said that imagegrabwindow() is not stable ? In this case how can I capture a web page sreen with php ?