Venosino1
29-08-2014, 15:37
Ciao a tutti.
Gestisco una webcam meteorologica (ww w.venosameteo.it/cam.php, link volutamente errato poichè c'è un antihotlink) e, come potete vedere, utilizzo un file php per sovrapporre all'immagine .jpg una barra contenente alcuni dati meteorologici e la data dello scatto.
Per la data viene letta quella di creazione dell'immagine jpg, inviata al server ogni 2-3 minuti.
Capita però che il pc si spenga e finchè non viene riavviato la webcam resta ferma. Quello che ho pensato è di sovrapporre la scritta "Webcam offline" all'immagine quando questa non viene aggiornata per un periodo di 15-20 minuti. Il problema è che non ho idea di come impostare il controllo sul "filemtime"...
Questo è il codice del .php:
<?
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$nome_immagine="cam.jpg"; // nome immagine webcam
$nome_testo="t.txt";
$nome_testo2="temp.txt";
$nome_testo5="umid.txt";
$nome_testo6="vent.txt";
$nome_testo7="pres.txt";
$nome_testo8="piog.txt";
$fp = fopen($nome_testo,"r")
or die("No txt file");
$fp2 = fopen($nome_testo2,"r")
or die("No txt file");
$fp5 = fopen($nome_testo5,"r")
or die("No txt file");
$fp6 = fopen($nome_testo6,"r")
or die("No txt file");
$fp7 = fopen($nome_testo7,"r")
or die("No txt file");
$fp8 = fopen($nome_testo8,"r")
or die("No txt file");
$testo_sinistra=fgets($fp,150);
$testo_destra=fgets($fp,50);
$testo_temp=fgets($fp2,50);
$testo_umid=fgets($fp5,50);
$testo_vent=fgets($fp6,50);
$testo_pres=fgets($fp7,50);
$testo_piog=fgets($fp8,50);
if ( $testo_destra = "data" )
{
setlocale(LC_TIME,"it_IT");
$testo_destra=strftime ("%d %B %Y, ore %H:%M", filemtime($nome_immagine));
}
fclose($fp);
fclose($fp2);
fclose($fp5);
fclose($fp6);
fclose($fp7);
fclose($fp8);
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg($nome_immagine);
$logo6 = imagecreatefrompng('barra2.png');
$logo7 = imagecreatefrompng('./icons/t2.png');
$logo8 = imagecreatefrompng('./icons/u2.png');
$logo9 = imagecreatefrompng('./icons/v2.png');
$logo10 = imagecreatefrompng('./icons/ps2.png');
$logo11 = imagecreatefrompng('./icons/p2.png');
$imagewidth = imagesx($im);
$imageheight = imagesy($im);
$logo6width = imagesx($logo6);
$logo6height = imagesy($logo6);
$logo7width = imagesx($logo7);
$logo7height = imagesy($logo7);
$logo8width = imagesx($logo8);
$logo8height = imagesy($logo8);
$logo9width = imagesx($logo9);
$logo9height = imagesy($logo9);
$logo10width = imagesx($logo10);
$logo10height = imagesy($logo10);
$logo11width = imagesx($logo11);
$logo11height = imagesy($logo11);
$startwidth = (($imagewidth - $logowidth) );
$startheight = (( $imageheight - $logoheight) );
$startwidth6 = (($imagewidth - $logo6width) );
$startheight6 = (( $imageheight - $logo6height) );
$startwidth7 = (($imagewidth - $logo7width) );
$startheight7 = (( $imageheight - $logo7height) );
$startwidth8 = (($imagewidth - $logo8width) );
$startheight8 = (( $imageheight - $logo8height) );
$startwidth9 = (($imagewidth - $logo9width) );
$startheight9 = (( $imageheight - $logo9height) );
$startwidth10 = (($imagewidth - $logo10width) );
$startheight10 = (( $imageheight - $logo10height) );
$startwidth11 = (($imagewidth - $logo11width) );
$startheight11 = (( $imageheight - $logo11height) );
$colore_testo = imagecolorallocate($im, 255, 255, 255);
$x=imagesx($im);
$y=imagesy($im);
$font = "verdana.ttf";
$size = 11;
$size2 = 11.5;
$size3 = 9;
$sizetestodestra = 10;
imagettftext($logo6, $size2, 0, 20, 21, $colore_testo, $font, 'Venosa (PZ) - 415m slm'); // nome località
imagettftext($logo6, $size3, 0, 1076, 27, $colore_testo, $font, '© www.venosameteo.it'); // copyright
imagettftext($logo6, $sizetestodestra, 0, 1060, 14, $colore_testo, $font, $testo_destra); // data e ora
$sizetemp = 18;
$colore_temp = imagecolorallocate($logo6, 255, 153, 0);
imagettftext($logo6, $size, 0, 300, 21, $colore_testo, $font, $testo_temp);
imagettftext($logo6, $size, 0, 402, 21, $colore_testo, $font, $testo_umid);
imagettftext($logo6, $size, 0, 643, 21, $colore_testo, $font, $testo_vent);
imagettftext($logo6, $size, 0, 500, 21, $colore_testo, $font, $testo_pres);
imagettftext($logo6, $size, 0, 830, 21, $colore_testo, $font, $testo_piog);
$info = getimagesize($nome_immagine);
imagecopy($im, $logo6, 0, 929, 0, 0, $logo6width, $logo6height);
imagecopy($im, $logo7, 270, 933, 0, 0, $logo7width, $logo7height);
imagecopy($im, $logo8, 372, 930, 0, 0, $logo8width, $logo8height);
imagecopy($im, $logo9, 610, 933, 0, 0, $logo9width, $logo9height);
imagecopy($im, $logo10, 465, 934, 0, 0, $logo10width, $logo10height);
imagecopy($im, $logo11, 795, 933, 0, 0, $logo11width, $logo11height);
imageinterlace($im, TRUE);
imagejpeg($im,"",93);
imagedestroy($im);
imagedestroy($logo6);
imagedestroy($logo7);
imagedestroy($logo8);
imagedestroy($logo9);
imagedestroy($logo10);
imagedestroy($logo11);
?>
Qualcuno sa aiutarmi?
Gestisco una webcam meteorologica (ww w.venosameteo.it/cam.php, link volutamente errato poichè c'è un antihotlink) e, come potete vedere, utilizzo un file php per sovrapporre all'immagine .jpg una barra contenente alcuni dati meteorologici e la data dello scatto.
Per la data viene letta quella di creazione dell'immagine jpg, inviata al server ogni 2-3 minuti.
Capita però che il pc si spenga e finchè non viene riavviato la webcam resta ferma. Quello che ho pensato è di sovrapporre la scritta "Webcam offline" all'immagine quando questa non viene aggiornata per un periodo di 15-20 minuti. Il problema è che non ho idea di come impostare il controllo sul "filemtime"...
Questo è il codice del .php:
<?
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$nome_immagine="cam.jpg"; // nome immagine webcam
$nome_testo="t.txt";
$nome_testo2="temp.txt";
$nome_testo5="umid.txt";
$nome_testo6="vent.txt";
$nome_testo7="pres.txt";
$nome_testo8="piog.txt";
$fp = fopen($nome_testo,"r")
or die("No txt file");
$fp2 = fopen($nome_testo2,"r")
or die("No txt file");
$fp5 = fopen($nome_testo5,"r")
or die("No txt file");
$fp6 = fopen($nome_testo6,"r")
or die("No txt file");
$fp7 = fopen($nome_testo7,"r")
or die("No txt file");
$fp8 = fopen($nome_testo8,"r")
or die("No txt file");
$testo_sinistra=fgets($fp,150);
$testo_destra=fgets($fp,50);
$testo_temp=fgets($fp2,50);
$testo_umid=fgets($fp5,50);
$testo_vent=fgets($fp6,50);
$testo_pres=fgets($fp7,50);
$testo_piog=fgets($fp8,50);
if ( $testo_destra = "data" )
{
setlocale(LC_TIME,"it_IT");
$testo_destra=strftime ("%d %B %Y, ore %H:%M", filemtime($nome_immagine));
}
fclose($fp);
fclose($fp2);
fclose($fp5);
fclose($fp6);
fclose($fp7);
fclose($fp8);
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg($nome_immagine);
$logo6 = imagecreatefrompng('barra2.png');
$logo7 = imagecreatefrompng('./icons/t2.png');
$logo8 = imagecreatefrompng('./icons/u2.png');
$logo9 = imagecreatefrompng('./icons/v2.png');
$logo10 = imagecreatefrompng('./icons/ps2.png');
$logo11 = imagecreatefrompng('./icons/p2.png');
$imagewidth = imagesx($im);
$imageheight = imagesy($im);
$logo6width = imagesx($logo6);
$logo6height = imagesy($logo6);
$logo7width = imagesx($logo7);
$logo7height = imagesy($logo7);
$logo8width = imagesx($logo8);
$logo8height = imagesy($logo8);
$logo9width = imagesx($logo9);
$logo9height = imagesy($logo9);
$logo10width = imagesx($logo10);
$logo10height = imagesy($logo10);
$logo11width = imagesx($logo11);
$logo11height = imagesy($logo11);
$startwidth = (($imagewidth - $logowidth) );
$startheight = (( $imageheight - $logoheight) );
$startwidth6 = (($imagewidth - $logo6width) );
$startheight6 = (( $imageheight - $logo6height) );
$startwidth7 = (($imagewidth - $logo7width) );
$startheight7 = (( $imageheight - $logo7height) );
$startwidth8 = (($imagewidth - $logo8width) );
$startheight8 = (( $imageheight - $logo8height) );
$startwidth9 = (($imagewidth - $logo9width) );
$startheight9 = (( $imageheight - $logo9height) );
$startwidth10 = (($imagewidth - $logo10width) );
$startheight10 = (( $imageheight - $logo10height) );
$startwidth11 = (($imagewidth - $logo11width) );
$startheight11 = (( $imageheight - $logo11height) );
$colore_testo = imagecolorallocate($im, 255, 255, 255);
$x=imagesx($im);
$y=imagesy($im);
$font = "verdana.ttf";
$size = 11;
$size2 = 11.5;
$size3 = 9;
$sizetestodestra = 10;
imagettftext($logo6, $size2, 0, 20, 21, $colore_testo, $font, 'Venosa (PZ) - 415m slm'); // nome località
imagettftext($logo6, $size3, 0, 1076, 27, $colore_testo, $font, '© www.venosameteo.it'); // copyright
imagettftext($logo6, $sizetestodestra, 0, 1060, 14, $colore_testo, $font, $testo_destra); // data e ora
$sizetemp = 18;
$colore_temp = imagecolorallocate($logo6, 255, 153, 0);
imagettftext($logo6, $size, 0, 300, 21, $colore_testo, $font, $testo_temp);
imagettftext($logo6, $size, 0, 402, 21, $colore_testo, $font, $testo_umid);
imagettftext($logo6, $size, 0, 643, 21, $colore_testo, $font, $testo_vent);
imagettftext($logo6, $size, 0, 500, 21, $colore_testo, $font, $testo_pres);
imagettftext($logo6, $size, 0, 830, 21, $colore_testo, $font, $testo_piog);
$info = getimagesize($nome_immagine);
imagecopy($im, $logo6, 0, 929, 0, 0, $logo6width, $logo6height);
imagecopy($im, $logo7, 270, 933, 0, 0, $logo7width, $logo7height);
imagecopy($im, $logo8, 372, 930, 0, 0, $logo8width, $logo8height);
imagecopy($im, $logo9, 610, 933, 0, 0, $logo9width, $logo9height);
imagecopy($im, $logo10, 465, 934, 0, 0, $logo10width, $logo10height);
imagecopy($im, $logo11, 795, 933, 0, 0, $logo11width, $logo11height);
imageinterlace($im, TRUE);
imagejpeg($im,"",93);
imagedestroy($im);
imagedestroy($logo6);
imagedestroy($logo7);
imagedestroy($logo8);
imagedestroy($logo9);
imagedestroy($logo10);
imagedestroy($logo11);
?>
Qualcuno sa aiutarmi?