I'm building a web page screen capture application for an internal R&D project.
Environment: Ubuntu 9.04 (default desktop install), Apache, PHP.
So far I've got a bash script that takes one parameter (URL), fires up firefox, grabs the screen and saves it as a PNG. I've tried running this from terminal and it works fine.
Here's the Bash script:
#!/bin/bash
firefox $1 # Start firefox and go to the passed in URL
scrot -d 5 test.png # Take screen grab with 5 second delay
Next I created a simple PHP page that uses shell_exec to run the script:
<?
// Sample URL
$url = 'http://www.google.com';
// Run the script
shell_exec('sh script.sh ' . $url);
// Out put HTML to display image
echo '<img src="test.png" />';
?>
However, when the PHP page is called the screen is not captured. A quick look in the apache error logs show the following message:
Error: no display specified giblib error: Can't open X display. It *is* running, yeah
I'm guessing this is because apache is running as a different user and hasn't got access to my X display.
So, can anyone shed any light on what I'm doing wrong or how I can capture the current user display.
Thanks.