Question

I'm trying to get imagegrabscreen (a GD function) to work with my Apache/Vista PC.

I'm using the following code:

<?php
$im = imagegrabscreen();

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

At the moment I get a solid black image, the size of my secondary monitor (1024*768). I'm using Apache 2.2, runing as a service, Vista SP1 with UAC off, PHP 5.2.8 and GD (information below). I've followed the note on the imagegrabscreen page about allowing Apache access to the desktop. I've also restarted the service and the apache server. I get the same results with imagegrabwindow.

Is this a bug (do other people have trouble running this method?) or is there something I'm doing wrong?

Array
(
    [GD Version] => bundled (2.0.34 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] => 1
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] => 
)

Apache Service Log On details:

http://www.kalleload.net/uploads/maogfnfnczfh.png http://www.kalleload.net/uploads/maogfnfnczfh.png

Was it helpful?

Solution

I looked at the source to imagegrabscreen();

at this point, I believe it is failing because we both have multi-monitor set-ups.

The current code calls GetDC(0), which according to http://msdn.microsoft.com/en-us/library/dd144871(VS.85).aspx should return the device context for "the entire screen", but "To get the DC for a specific display monitor, use the EnumDisplayMonitors and CreateDC functions"

I am going to do a bit more testing of this and see if I can come up with multi-monitor-friendly code.

OTHER TIPS

I see Hugh's currently checked answer, and am curious if anyone has solved this in the last 3 years? I have followed the "allow service to interact with the desktop" steps, and am running on a laptop that I occasionally connect a second monitor too. Though when I am using the script that I am trying to make this work with, I will only be on my laptops main monitor. I am running Windows 7 64bit, with WAMP Server 2.2. The php_gd2 extension is checked, and it works with saving the file. But no matter what I try, and all the findings, I can not get this thing to screenshot properly, it always returns a black screen. I have also tried the basic code provided in this example (though mine was pretty much the same thing anyway).

If anyone can provide me a solution if they found one, please let me know, I would greatful. I have even tried running WAMP in compatibility mode with XP and Vista :/ (I read somewhere that the imagegrabscreen function only works with XP/Vista. Ultimately I am trying to create a small lightweight script that I can have run in the background to monitor progress on a project I am working on, which simply snaps a screenshot, sizes it down a bit, and at the end of my days work, it would zip up the files and pass them to the user in email. Everything else works with ease, but it is my first time using the imagegrabscreen function, and as cool as it sounds, it has now gotten to my nerves cause I cant get it to just do its job... :(

I have duplicated this error - WinXP SP3, Apache 2.2.11 running as a service, PHP 5.2.8, GD 2.0.34 bundled.

I allowed interaction with the desktop and restarted the service. On a dual-screen setup (Primary: 1440x900, Secondary: 1920x1200) I get a black rectangle the size of the primary screen. I have error reporting turned right up (E_ALL | E_STRICT) and XDebug does not report any errors.

Does anyone else care to take a shot at this? Most important variables seem to be OS (Win2000/WinXP/Win2003/Vista) and version of PHP (5.2.2/.3/.4/.5/.6/.8).

I am going to take a peek at the source to imagegrabscreen().

I think imagegrabscreen() only works in Windows XP not Vista.
You should check this link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top