I'm trying to capture a local web page with imagegrabscreen but I only get a black screenshot. I tried almost every solution from questions here on SO and others sites and nothing works.
I'm using and done the following:
<?php
$im = imagegrabscreen();
imagepng($im, "myscreenshot.png");
imagedestroy($im);
?>
And all I get is a black image 1024x768 png.
You can do it. I did this. I didn't use WAMP. I used everything separate. I have all PHP, MySQL and Apache setup.
Here are the steps.
Stop the Apache server service. You can do this by invoking
NET STOP Apache2.2
or you can open the services.msc
then stop it.
Copy the Apache2.2
folder out of C:\
. Put it somewhere where you have full access. Like Documents
or in other drive. I put it in K:
. To be sure you have full access,
Full control
marked tick on security tab of the Apache2.2
folder. httpd.conf
will contain a lot of hardcoded paths. Like C:\apache software foundation\apache2.2
. Just replace those with your new path. In my case it was K:\Apache2.2
.At this moment your Apache Server Service should be stopped. So 80 port will not be blocked. And you'll have your own Apache at your own territory (directory).
Open a console window and go to your Apache home where htdocs
folder resides along with some other folders using cd
bin\httpd.exe
. This means you are running Apache. You have full access to your desktop. You can do anything, so do httpd.exe
Open your web page. With following code.
<?php
header("Content-type: image/png");
$im = imagegrabscreen();
imagepng($im);
imagedestroy($im);
exit(0);
?>
You'll see the image.