Peter K.
Peter K.

Reputation: 78

How can I create a inmemory screencapture with php at unix (debian)

The following code, is only available on windows.

<?php
  ...
  $im = imagegrabwindow($handle);
  ...      
  imagedestroy($im);
?>

Whats the solution on unix (debian) php environment, get the screen capture at a php cli programm?

Upvotes: 1

Views: 256

Answers (1)

wimvds
wimvds

Reputation: 12850

So, it sounds like you want to capture screens from Firefox :p.

For a headless server, make sure Xvfb is installed first, then start it with Xvfb :2 -screen 0 1024x768x24& (you can change the display :2 and resolution 1024x768x24 as needed of course).

Run Firefox to open a specific page on that display DISPLAY=:2 firefox http://www.example.com. Wait a bit for Firefox to open the page, so execute a sleep 10 or something similar.

And then throw in some "magic" from ImageMagick (which has to be installed of course) to capture the screen to a file : import -window root -display :2 example.png.

And now your processing fun starts :p.

Here's a small bash script putting it all together (Xvfb should already be running though for it to work) :

#!/bin/bash
export DISPLAY=":2" /usr/bin/firefox "$1"&
/bin/sleep 10
/usr/bin/import -window root -display :2 "$2"
killall firefox-bin

Call that from PHP, and provide it with the URL and filename of the screenshot as parameters.

btw If your server has X you can skip the Xvfb part and use the running X server display (most probably :0).

Upvotes: 1

Related Questions