http://moi.homeip.net/~pol/site/php/ssgrabber/index.php
<?
error_reporting(1);
// By Dell'aiera Pol
// blenderman@wanadoo.be
// Copyright under GNU GPL
$temp = $_SERVER["SCRIPT_FILENAME"];
$temp = explode ("/",$temp);
array_pop($temp);
$directory = implode("/",$temp);
extract($_GET);
/*
$quality = $_GET["quality"];
$size = $_GET["size"];
$viewsrc = $_GET
*/
echo "<fieldset><legend>Some informations</legend>";
echo "This page will take a screenshot of my current screen. Just select the quality of the screenshot and the size of it.";
echo "<p align=right>Dell'Aiera Pol</p>";
echo "</fieldset>";
//$fichier = date("dmYhis");
$fichier = explode(" ",microtime());
$fichier = $fichier[1];
$filename = "$fichier.jpg";
$date=time();
//$filedate = filemtime($filename);
function clean_old_png()
{
$handle = opendir(".");
while (false != ($trash = readdir($handle)))
{
if (eregi("jpg",$trash) && !eregi("temp",$trash))
{
$list[$trash] = filectime($trash);
}
}
asort($list);
$i = 10;
$size = count($list);
if (count($list) > 10)
{
reset($list);
for ( $j=0 ; ($size-10)>=$j ; $j++)
{
//echo "<br>le fichier ".key($list)." doit etre efface</br>";
unlink(key($list));
next($list);
}
}
}
function take_the_shot($quality,$size)
{
global $directory;
//echo "quality: ->".strlen($quality)."<br>size: $size".strlen($size)."<br>";
if ((strlen($quality) < 4) && (strlen($size) < 4))
{
global $filename;
$size = $size."%";
$temp = "/usr/bin/import -display :0.0 -silent -depth 8 -geometry $size% -quality $quality -window root $type $directory/$filename";
//$temp = "/usr/bin/import -display :0.0 -window root $type $directory/$filename";
//echo "Commande: $temp<br>";
$result = exec("$temp");
//echo "Resultat: $result<br>";
}
}
function add_timestamp($imgname)
{
global $date,$filename,$directory;
//$im = imagecreatefrompng ($imgname); /* Attempt to open */
$src = "$directory/$imgname";
$im = imagecreatefromjpeg($src); /* Attempt to open */
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
$date_h = gmdate("H:i:s",$date);
imagefilledrectangle($im,0,0,imagesx($im),9,$black);
imagestring($im,1,0,0,"Taken by $_SERVER[REMOTE_ADDR] @ $date_h",$white);
//imagepng($im,$filename,100);
imagejpeg($im,$filename,100);
imagedestroy($im);
}
if ($quality)
{
//echo "Take the shot<br>";
take_the_shot ($quality,$size);
add_timestamp($filename);
}
echo "<html>";
echo "<head><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">";
echo "<title>Screenshot grabber in realtime</title></head><body>";
echo "<fieldset><legend>Quality of the screenshot</legend>";
$tab = array(1,5,10,20,30,40,50,60,70,80,90,100);
echo "<form action=\"index.php\" method=\"get\">"
."<select name=quality>";
for ($i=0;$i<count($tab);$i++)
{
if ($quality == $tab[$i])
{
echo "<option name=$tab[$i] value=$tab[$i] selected>$tab[$i]</option>";
}
else
{
echo "<option name=$tab[$i] value=$tab[$i]>$tab[$i]</option>";
}
}
echo "</select>";
echo "</fieldset>";
echo "<fieldset><legend>Size of the screenshot</legend>";
$tab = array(10,20,30,40,50,60,70,80,90,100);
echo "<select name=size>";
for ($i=0;$i<count($tab);$i++)
{
if ($size == $tab[$i])
{
echo "<option name=$tab[$i] value=$tab[$i] selected>$tab[$i] %</option>";
}
else
{
echo "<option name=$tab[$i] value=$tab[$i]>$tab[$i] %</option>";
}
}
echo "</select>";
echo "</fieldset>";
echo "<input type=submit value=\"Take the Screenshot\">"
."</form>";
if ($quality)
{
copy($filename,"temp.jpg");
echo "<table align=center cellspacing=0 cellpadding=2 bgcolor=000000><tr><td>";
echo "<img src=$filename>";
echo "</td></tr></table>";
}
if (!$quality) ($quality = 50);
clean_old_png();
include("viewsrc.inc.php");
echo "</body></html>";
?>