我正在为一个内部研发项目构建一个网页截屏应用程序。
环境:Ubuntu 9.04(默认桌面安装)、Apache、PHP。
到目前为止,我有一个 bash 脚本,它接受一个参数(URL),启动 firefox,抓取屏幕并将其保存为 PNG。我试过从终端运行它,它工作正常。
这是 Bash 脚本:
#!/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
接下来我创建了一个简单的 PHP 页面,它使用 shell_exec 来运行脚本:
<?
// 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" />';
?>
但是,当调用 PHP 页面时,不会捕获屏幕。快速查看 apache 错误日志会显示以下消息:
Error: no display specified giblib error: Can't open X display. It *is* running, yeah
我猜这是因为 apache 以不同的用户身份运行并且无法访问我的 X 显示器。
那么,任何人都可以阐明我做错了什么或如何捕获当前用户显示。
谢谢。