1

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

Ross
  • 46,186
  • 39
  • 120
  • 173
  • Just an random idea but have you tried disabling UAC? – gradbot Mar 10 '09 at 17:39
  • I have that off. Apache is also running as the local user - presumably myself - and that is an Administrator user. – Ross Mar 10 '09 at 17:49
  • Is Apache running as a service, and with access to the display (was a check box in w2k)? – Ryann Graham Mar 10 '09 at 17:55
  • Apache is running as a service. I can't find any "access to display" checkboxes though. I'll post a screenshot of the Log On tab for the service. – Ross Mar 10 '09 at 17:57
  • It was the "allow service to interact with desktop" checkbox that I was referring to, which I see is checked. – Ryann Graham Mar 10 '09 at 22:04

2 Answers2

1

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.

Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
  • That's great news Hugh. If you do make a patch for it could you contact Pierre (irc.freenode.org #libgd) to ask about including it? Thanks! – Ross Mar 11 '09 at 20:35
0

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

Alex Essilfie
  • 12,339
  • 9
  • 70
  • 108
Arslan
  • 169
  • 2
  • 2
  • 8