tags:

views:

634

answers:

7

Hi There

I am hoping that there is someone that can help me and many others with this problem...

I want to create a screenshot of a website using the imagegrabwindow function part of php and the GD library

After spending the whole day implementing the code I finally can capture the image and save it to a file, but the image is black and not the image that I expected...

On further investigation I have learned that one of the reasons why the image is black is because apache is not turned on to interact with the desktop - and because of this creates a black image - The issue is I am not running Apache as a server I am running IIS 6...

Is there a setting in Services that I should allow to interact with the desktop? and if there is can somebody point me in the right direction?

<?php
    $browser = new COM("InternetExplorer.Application");
    $handle = $browser->HWND;
    $browser->Visible = true;
    $browser->Fullscreen = true;
    $browser->Navigate("http://localhost/site/advertise/index.asp");

    /* Still working? */
    while ($browser->Busy) {
        com_message_pump(4000);
    }
    $im = imagegrabwindow($handle, 0);
    imagepng($im, "iesnap6.jpg");
    $browser->Quit();
    ?>

Thanks to the answers below I have changed imagepng to imagejpeg - But still get a black image...

imagejpeg($im, "iesnap7.jpg");

Any help would be much appreciated!

Thanks

I have ammended the code to this: Social Addict still no success with the image showing up in Black!

  <?php
 header('Content-type: image/jpeg');
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://localhost/advertise/index.asp");

/* Still working? */
while ($browser->Busy) {
    com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagejpeg($im," file2.jpg");
imagedestroy($im);
?>

Social Addict - I have added the header - I am also constantly changing the file1.jpg name to make sure it is not using a black cached images... still no luck!

+2  A: 

I've had this problem before and is often caused when you try and load or convert an image to an incorrect type

I think it may be something to do with this line

imagepng($im, "iesnap6.jpg");

You are saving it as a png and naming it as a jpg here.

Try the following as you have stated you want jpeg

imagejpeg($im, "iesnap6.jpg");

instead

Try setting the header type before the imagejpeg call:

header('Content-type: image/jpeg');

then accessing the script from the browser directly and see if that works?

Also this is another known issue from PHP.NET

This function was painfully slow when I was testing it on my machine. It took about 2 or 3 seconds for it to return an image. It also fails to work if the Apache service doesn't have access to "Interact with the desktop"

Andi
I have changed it to imagepng($im, "iesnap6.pmh"); as well and get the same black image - I do not have Appache installed only running "IIS" as my webserver - which make me thing that I should somehow allow IIS to "Interact with the desktop"
Gerald Ferreira
I mean imagepng($im, "iesnap6.png"); (Spelling Correction)
Gerald Ferreira
go to your iis settings and allow interact with desktop. But the line you just wrote doesnt match to what i suggested... imagejpeg($im," file.jpg");
Andi
Thanks SocialAddict - changed it to imagejpeg($im," file.jpg"); (Still a black image) in settings I cannot find IIS as a service and are assuming it is World Wide Web Publishing Service and allowed "interact with desktop" restarted and made sure the service is running - but still getting a black image...
Gerald Ferreira
You need to call the browser commit command before the imagejpeg() call -or the example on php.net seems to: http://php.oregonstate.edu/manual/en/function.imagegrabwindow.php
Andi
try setting the header type as ive amended above
Andi
A: 

Are the IIS and WWW Publishingservice allowed to interact with the desktop?

My computer -> manage -> services -> [IIS and WWWPub...] -> LoginTab -> Allow to interact with desktop

jitter
I am running Vista - ->Services->World Wide Web Publishing Service-> LoginTab -> Allow to interact with desktop Assuming that it is the same as [IIS and WWWPub...] do not have the [IIS and WWWPub...] restarted my machine and checked if the service restarted... still getting the Black image
Gerald Ferreira
A: 

i had the same problem, try change color resolution to 32 bits and try again.

Jaas
Thanks for comming back to me Jass - One of the problems is that my server only handles 16 bit
Gerald Ferreira
A: 

I've check things with the 16bits and 32 bits as well but it still not works

bhaumik
A: 

i m using same code but still i m gettimg black image, anyone please help me out.

Deepak Raikwar
A: 

I was having problems with imagegrabwindow(). Eventually, after finding no help with the problem, I decided to see if I could script an existing page-capture plugin or extention. I found that Pearl Crescent Page Saver for Firefox is scriptable from the commandline.

http://pearlcrescent.com/products/pagesaver/doc/#commandline

The Basic version gives you less flexibility than their paid version, but the basic version met my needs. It may also work on non-Windows systems, but I haven't tried it.

Greg Bulmash
A: 

I have figured out the issue a while back: The main problem were that my dedicated server did not have a 32 bit Graphics Card Installed. This caused the images to display black...

I updated my server hardware and installed a 32 bit graphics card and now it is working with no issues.

Gerald Ferreira