http://kicken.mine.nu:8008/extras/webshot/ss_daemon `#!/usr/local/bin/php -q
<?php
/************************************************
* Screen Capture script *
* Written by: Keith (aka kicken) *
* Email: keithm@aoeex.com *
* *
* What's it do? *
* This script takes a URL and creates a *
*graphic of the url that can be displayed. *
* *
* How's it do that? *
* It's quite simple, but does require a *
*few things. First, you need some sort of a *
*web browser that can be called up with a *
*defualt URL on the command line and supports *
*javascript. Second, you need to have *
*Imagemagick (specifically the import *
*command). This is used to take a screen *
*capture a few seconds after the web browser *
*has been launched. *
************************************************/
$path_to_browser='/usr/local/bin/mozilla';
$path_to_import='/usr/X11R6/bin/import';
$path_to_output='/home/kicken/data/extras/webshot/images';
$path_to_redirect='file:///home/kicken/data/extras/webshot/ss.html';
$crop='781x549+2+44';
$format='.jpg';
$quality=85;
$timeout=60;
//// Stop Editing Here!!!!!! //////
function fixchars($str){
return preg_replace('/[^a-zA-Z0-9_]/', '_', $str);
}
set_time_limit(0);
include('mysql_connect.php');
while ($res=mysql_query('SELECT ID, url FROM ss_que')){
while ($row=mysql_fetch_object($res)){
$url=$row->url;
//First, we launch the browser with the url, escape shell characters to avoid hacks.
//We don't want to wait for the browser.
echo 'Launching browser with the url ', $url, '.', chr(10);
$browserargs=$path_to_redirect.'?'.urlencode($url);
system($path_to_browser.' '.escapeshellarg($browserargs).' >/dev/null 2>&1 &');
//Now we wait for the browser to launch.
echo 'Sleeping for ', $timeout, ' seconds while things load and get rendered...';
flush();
sleep($timeout);
echo chr(10);
echo 'Taking a screen capture and saving to path: ', $path_to_output, '/', fixchars($url), chr(10);
flush();
//Now, we take a screen capture.
system($path_to_import.' -silent -window root -crop '.$crop.' -quality '.$quality.' '.$path_to_output.'/'.fixchars($url).$format);
echo 'Finished. The screen capture has been saved to: ', $path_to_output, '/', fixchars($url), $format;
mysql_query('DELETE FROM ss_que WHERE id="'.$row->ID.'"') or die('Unable to delete from que'.mysql_error());
}
sleep(1);
}
?>
`