Codice PHP:
<?php
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->user = "admin";
$snoopy->pass = "";
$imgurl = "http://host/snapshot.cgi?user=admin&pass=";
$imgfilename = "carrera.jpg";
/* cache the files locally */
if (!file_exists($imgfilename) || filemtime($imgfilename) + 300 < time()) { // 5min cache
global $snoopy;
$snoopy->fetch($imgurl);
file_put_contents($imgfilename, $snoopy->results);
$snoopy->results = '';
}
header("Content-type: image/jpg");
$new_image = imagecreatefromjpeg($imgfilename);
$x=imagesx($new_image);
$y=imagesy($new_image);
$ratio = 250 / $x;
$height = $y * $ratio;
$im = imagecreatetruecolor(250, $height);
imagecopyresampled($im, $new_image, 0, 0, 0, 0, 250, $height, $x, $y);
$x=imagesx($im);
$y=imagesy($im);
date_default_timezone_set('Europe/Rome');
setlocale(LC_TIME,"it_IT");
$testo_destra=strftime ("%d %b %H:%M", filemtime($imgfilename));
$colore_barra = imagecolorallocate($im, 0, 80, 225); // colore della barra formato RGB
$colore_testo = imagecolorallocate($im, 255, 255, 255); // idem per testo
$font = "FRAMDCN.TTF";
$size = 12; // dimensione del testo
$altezza_barra = 22; // dimensione della barra
imagefilledrectangle($im, 0, $y-$altezza_barra, $x-1, $y-1, $colore_barra);
$testo_sinistra = "Via la Carrera";
$bbox = imagettfbbox ($size, 0, $font, $testo_sinistra);
$dy = (($bbox[1] - $bbox[7]) / 2);
imagettftext($im, $size, 0, 5, $y-($altezza_barra / 2) + $dy, $colore_testo, $font, $testo_sinistra);
$bbox = imagettfbbox ($size, 0, $font, $testo_destra);
$dx = ($bbox[2] - $bbox[0]);
imagettftext($im, $size, 0, $x-5-$dx, $y-($altezza_barra / 2) + $dy, $colore_testo, $font, $testo_destra);
imagejpeg($im,"",100);
imagedestroy($im);
?>