I have asked this question about once every 6 months, because I am hopeful I will one day have a better answer. So here goes again.
Are there any good methods for grabbing screenshots using PHP?
(preferably on a Linux server)
I have asked this question about once every 6 months, because I am hopeful I will one day have a better answer. So here goes again.
Are there any good methods for grabbing screenshots using PHP?
(preferably on a Linux server)
Chances are that there isn’t a screen attached to the server most of the time fro PHP to get a screenshot from (since most hosts probably switch one screen between dozens if not hundreds of different servers). What is on the screen usually would have no relevance to a given PHP script even where there is a screen attached to that server.
There are actually a few image libraries that PHP has native extensions available for Things like GD and ImageMagick both have the ability to capture a screen or a window. GD i probably the easiest to use.
See http://www.php.net/manual/en/function.imagegrabscreen.php
[COLOR=#000000][COLOR=#0000bb]
<?php
$im = imagegrabscreen();
imagepng($im, "myscreenshot.png");
?>
[/COLOR][/COLOR]
To capture a single window look at
http://www.php.net/manual/en/function.imagegrabwindow.php
[COLOR=#000000][COLOR=#0000bb]
<?php
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.libgd.org");
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
?>
These work on multiple operating systems. [/COLOR][/COLOR]
imagegrabscreen is only on Windows.
I found one decent one for windows also, but not platform independent.
you can try to get an idea from http://browsershots.org/ gues.
you can try to get an idea from http://browsershots.org/ guys.
On linux servers it’s impossible to grab the screen since there is no x-server running
Browsershots gets images from linux client drone machines, not server machines. Server machines don’t have display managers or graphical browsers installed as they only drain memory/cpu
I did finally figure out a solution, and it will likely be announced in the marketplace soon. I tried several different strategies, and I could never find what really needed, so hopefully I can provide something that will be helpful to others too.
The main problem with making screenshots of pages is that you need a complete HTML, JS, CSS and Image rendering engine to output - I think the only way would be to have a machine devoted to graphical displays, but the output would depend on the browser it uses.
The other problem is, that none of the Linux based browsers support a direct way for an external application to know when a page has loaded. There is no system wide onload event triggered that would tell the external app, when the page was completely loaded.
You would have to come up with something that embedded the gekko engine, had a fake display driver that simply saved the rendered output to a buffer which could then be saved in an image format. I have yet to see anybody do that in a free tool, although the software is there to do it. there are some scripts available that try to use a settable timeout for the screen shot, but if the page is slow to load for any reason, you may get nothing.
You also likely wouldn’t want the browser chrome or KDE/GNOME desktop in the screen shot, which would eliminate certain simple methods for getting screen output.
how about this: http://www.guangmingsoft.net/htmlsnapshot/html2image.htm
which is based on this: http://www.xfree86.org/4.4.0/Xvfb.1.html
?