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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
linphp
Forum Newbie
Posts: 4
Joined: Thu Sep 25, 2008 9:52 pm

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

Post 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");
?>
 
 
linphp
Forum Newbie
Posts: 4
Joined: Thu Sep 25, 2008 9:52 pm

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

Post by linphp »

guys help
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

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

Post by onion2k »

What have you done to try and work out what the problem is?
linphp
Forum Newbie
Posts: 4
Joined: Thu Sep 25, 2008 9:52 pm

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

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

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

Post 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.
linphp
Forum Newbie
Posts: 4
Joined: Thu Sep 25, 2008 9:52 pm

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

Post 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 ?
Post Reply