Codice PHP:
<?php
if ( isset($nome_file) )
{
$nome_immagine=$nome_file.".jpg"; // file contenente l'immagine
$nome_testo=$nome_file.".txt"; // file contenente le scritte
}
else
{
$nome_immagine="webcam.jpg"; // file contenente l'immagine
$nome_testo="testo.txt"; // file contenente le scritte
}
if ( !isset($primadati) )
{
$primadati=1; // prima la barra dati poi la barra testo
}
$fp = fopen($nome_testo,"r")
or die("impossibile aprire il file $nome_testo.");
$testo_sinistra=fgets($fp,100); // nella prima riga la scritta allineata a sinistra
$testo_destra=fgets($fp,100); // nella seconda riga la scritta allineata a destra
if ( $testo_destra = "data" )
{
setlocale(LC_TIME,"it_IT");
$testo_destra=strftime ("%a %d %b %Y %H:%M:%S", filemtime($nome_immagine));
}
if ( $testo_destra = "exif" )
{
$exif = exif_read_data($nome_immagine, 0, true);
$testo_destra=$exif["IFD0"]["DateTime"];
}
while ( ! feof($fp) )
{
$dato[]=fgets($fp,100); // nella terza,quarta,quinta,sesta... riga i dati
}
fclose($fp);
header("Content-type: image/png");
$im0 = imagecreatefromjpeg($nome_immagine);
$altezza_barra = 18; // dimensione delle barre
$x=imagesx($im0);
$y=imagesy($im0);
if ( count($dato) )
{
$y1=$altezza_barra*2;
}
else
{
$y1=$altezza_barra;
}
$im = imagecreatetruecolor($x,$y+$y1);
imagecopy ( $im, $im0, 0, 0, 0, 0, $x, $y );
$y=$y+$y1;
if (( $primadati ) || ( !count($dato) ))
{
$ofsdati=2;
$ofstesto=1;
}
else
{
$ofsdati=1;
$ofstesto=2;
}
$font = "VeraBd.ttf";
$size = 8; // dimensione del testo
//$black = imagecolorallocate($im, 0, 0, 0);
//$white = imagecolorallocate($im, 255, 255, 255);
$colore_barratesto = imagecolorallocate($im, 1, 0, 128); // colore della barra testo formato RGB
$colore_testobt = imagecolorallocate($im, 255, 255, 255); // idem per testo barra testo
$colore_barradati = imagecolorallocate($im, 1, 0, 170); // colore della barra dati formato RGB
$colore_testobd = imagecolorallocate($im, 255, 255, 255); // idem per testo barra dati
// colora la barra testo
imagefilledrectangle($im, 0, $y-$ofstesto*$altezza_barra, $x-1, $y-($ofstesto-1)*$altezza_barra-1, $colore_barratesto);
// testo allineato a sinistra
$bbox = imagettfbbox ($size, 0, $font, $testo_sinistra);
$dy = (($bbox[1] - $bbox[7]) / 2);
imagettftext($im, $size, 0, 5, $y-($ofstesto-1)*$altezza_barra-($altezza_barra / 2) + $dy - 1, $colore_testobt, $font, $testo_sinistra);
// testo allineato a destra
$bbox = imagettfbbox ($size, 0, $font, $testo_destra);
$dx = ($bbox[2] - $bbox[0]);
imagettftext($im, $size, 0, $x-5-$dx, $y-($ofstesto-1)*$altezza_barra-($altezza_barra / 2) + $dy - 1, $colore_testobt, $font, $testo_destra);
if ( count($dato) )
{
// colora la barra dati
imagefilledrectangle($im, 0, $y-$ofsdati*$altezza_barra, $x-1, $y-($ofsdati-1)*$altezza_barra-1, $colore_barradati);
// dato[1] allineato a sinistra
$bbox = imagettfbbox ($size, 0, $font, $dato[0]);
$dy = (($bbox[1] - $bbox[7]) / 2);
imagettftext($im, $size, 0, 5, $y-($ofsdati-1)*$altezza_barra-$altezza_barra/2 + $dy - 1, $colore_testobd, $font, $dato[0]);
// dato[n] allineato a destra
$bbox = imagettfbbox ($size, 0, $font, $dato[count($dato)-1]);
$dx = ($bbox[2] - $bbox[0]);
imagettftext($im, $size, 0, $x-5-$dx, $y-($ofsdati-1)*$altezza_barra-$altezza_barra/2 + $dy - 1, $colore_testobd, $font, $dato[count($dato)-1]);
for ($i = 1; $i < count($dato)-1; $i++)
{
// dato[$i] allineato a $i/(count($dato)-1)
$bbox = imagettfbbox ($size, 0, $font, $dato[$i]);
$dx = ($bbox[2] - $bbox[0])/2;
imagettftext($im, $size, 0, ($x*$i)/(count($dato)-1)-$dx, $y-($ofsdati-1)*$altezza_barra-$altezza_barra/2 + $dy - 1, $colore_testobd, $font, $dato[$i]);
}
}
imagepng($im);
imagedestroy($im);
?>
per chi è interessato puo vedere tale script in funzione qui: