Eccomi, sono riuscito a partorire qualcosa:
Codice PHP:
<?php
if(isset($_POST['submit'])&&($_POST['submit']=="Invia"))
{
if(isset($_POST['mis_fin_lun']))
{
// supponiamo 3200
$mis_fin_lun = addslashes(filter_var($_POST['mis_fin_lun'], FILTER_SANITIZE_STRING));
$testo_mis_fin_lun = $mis_fin_lun;
}
if(isset($_POST['mis_fin_lar']))
{
// supponiamo 1400
$mis_fin_lar = addslashes(filter_var($_POST['mis_fin_lar'], FILTER_SANITIZE_STRING));
$testo_mis_fin_lar = $mis_fin_lar;
}
// imposto i parametri max di visualizzazione
$max_size_larg = 600; // in pixel
$max_size_alt = 600; //in pixel
$bordo = 5;
// mis_fin_lun = max_size_larg || mis_fin_lar = max_size_alt
if($mis_fin_lun > $max_size_larg)
{
$op1 = $mis_fin_lun / $max_size_larg; // 3200/400=8mm/px
$op1a = $mis_fin_lun / $op1; // 3200/8=400px
$op2 = $mis_fin_lar / $op1; // 1400/8=175px
$mis_fin_lun = $op1a; // 3200->400
$mis_fin_lar = $op2; // 1400->175
if($op2 > $max_size_alt)
{
$op3 = $mis_fin_lar / $max_size_alt; // 1400/160=8,75mm/px
$op3a = $mis_fin_lar / $op3; // 1400/8,75=160px
$op4 = $mis_fin_lun / $op3; // 3200/8,75=365px
$mis_fin_lun = $op4; // 3200->365
$mis_fin_lar = $op3a; // 1400->160
}
}elseif($mis_fin_lar > $max_size_alt){
$op6 = $mis_fin_lar / $max_size_alt; // 1400/160=8,75
$op6a = $mis_fin_lar / $op6; // 1400/8,75=160
$op7 = $mis_fin_lun / $op6; // 3200/8,75=365
$mis_fin_lun = $op7;
$mis_fin_lar = $op6a;
}else{
}
$size_testo = 5;
// testo centrato con l'immagine
$px_testo = imagefontwidth($size_testo); // misuro la dimensione del font
$larghezza_lun = strlen($mis_fin_lun); // misuro il numero di caratteri del font
$larghezza_lar = strlen($mis_fin_lar);
$larghezza_px_lun = $px_testo * $larghezza_lun;
$larghezza_px_lar = $px_testo * $larghezza_lar;
$testo_cent_lun = ($mis_fin_lun + $bordo)-((($mis_fin_lun + $bordo)/2)-($bordo/2));
$testo_cent_lar = ($mis_fin_lar + $bordo)-((($mis_fin_lar + $bordo)/2)-($bordo/2));
//$testo_cent_lun = ($mis_fin_lun + $bordo + $bordo) / 2;
//$testo_cent_lar = ($mis_fin_lar + $bordo + $bordo) / 2;
/*if($mis_fin_lun < $larghezza_px_lun)
{
$mis_fin_lun = $larghezza_px_lun;
$testo_cent_lun = (($mis_fin_lun + $bordo) / 2);
}
if($mis_fin_lar < $larghezza_px_lar)
{
$mis_fin_lar = $larghezza_px_lar;
$testo_cent_lar = (($mis_fin_lar + $bordo + $bordo) / 2);
}
*/
$img = imagecreatetruecolor($mis_fin_lun + $bordo, $mis_fin_lar + $bordo);
$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 000, 000);
$green = imagecolorallocate($img, 000, 255, 000);
$blue = imagecolorallocate($img, 000, 000, 255);
$black = imagecolorallocate($img, 000, 000, 000);
imagefilledrectangle($img, $bordo, $bordo, $mis_fin_lun, $mis_fin_lar, $white);
$colore_testo = $blue;
imagestring($img,$size_testo,$testo_cent_lun,5,$testo_mis_fin_lun,$colore_testo); // orizzontale
imagestringup($img,$size_testo,5,$testo_cent_lar,$testo_mis_fin_lar,$colore_testo); // verticale
imagejpeg($img, "image/img.jpg");
imagedestroy($img);
echo "<img src=\"image/img.jpg\"></img>";
echo "
";
}else{
echo "<form action=". $_SERVER['PHP_SELF'] ." method=\"post\">";
echo "Misura finita: ";
echo "<input name=\"mis_fin_lun\" value=\"lunghezza\" type=\"text\" maxlength=\"7\" size=\"7\">";
echo "<input name=\"mis_fin_lar\" value=\"larghezza\" type=\"text\" maxlength=\"7\" size=\"7\">";
echo "(prima misura senso vena)";
echo "
";
echo "<input name=\"submit\" type=\"submit\" value=\"Invia\">";
echo "</form>";
}
?>
Il mio problema ora è che non riesco a centrare perfettamente il testo nell'immagine .... qualche suggerimento?
Ho provato di tutto, ho giocato con
Codice PHP:
$testo_cent_lun = ($mis_fin_lun + $bordo)-((($mis_fin_lun + $bordo)/2)-($bordo/2));
$testo_cent_lar = ($mis_fin_lar + $bordo)-((($mis_fin_lar + $bordo)/2)-($bordo/2));
//$testo_cent_lun = ($mis_fin_lun + $bordo + $bordo) / 2;
//$testo_cent_lar = ($mis_fin_lar + $bordo + $bordo) / 2;
/*if($mis_fin_lun < $larghezza_px_lun)
{
$mis_fin_lun = $larghezza_px_lun;
$testo_cent_lun = (($mis_fin_lun + $bordo) / 2);
}
if($mis_fin_lar < $larghezza_px_lar)
{
$mis_fin_lar = $larghezza_px_lar;
$testo_cent_lar = (($mis_fin_lar + $bordo + $bordo) / 2);
}
*/
ma non ho ottenuto risultati soddisfacenti ...