Codice:
//parametri: #directory,#larghezza,#altezza,#testo, formati supportati: @jpg,@gif,@png.
function CreaThumb($src, $w, $h,$testo){
$size = getimagesize($src);
if( $size[2] == 2 ){$im = @imagecreatefromjpeg($src);}
elseif( $size[2] == 1 ){$im = @imagecreatefromgif($src);}
elseif( $size[2] == 3 ){$im = @imagecreatefrompng($src);}
$newwidth = $size[0];
$newheight = $size[1];
if( $newwidth > $w ){
$newheight = ($w / $newwidth) * $newheight;
$newwidth = $w;
}
if( $newheight > $h ){
$newwidth = ($h / $newheight) * $newwidth;
$newheight = $h;
}
if($size[2] != 1){
$new = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($new, $im, 0, 0, 0, 0, $newwidth, $newheight, $size[0], $size[1]);
}
else{
$new = imagecreate($newwidth, $newheight);
imagecopyresized($new, $im, 0, 0, 0, 0, $newwidth, $newheight, $size[0], $size[1]);
}
$textcolor = imagecolorallocate($new, 255, 255, 255);
//gestione posizione e dimensione testo
imagestring($new, 3, 1, 1, $testo, $textcolor);
header('Content-Type: ' . $size['mime']);
if( $size[2] == 2 ){@imagejpeg($new, '', 100);}
elseif( $size[2] == 1 ){@imagegif($new);}
elseif( $size[2] == 3 ){@imagepng($new);}
@imagedestroy($im);
@imagedestroy($new);
}
puoi richiamarla con una cosa del genere:
Codice:
//seleziona con un intero la cartella:
$selezione_dir = $_GET['id'];
//il nome dell'immagine
$imgs = $_GET['foto'];
switch($selezione_dir){
case 1:
break;
$foto="cartella1/".$imgs.".jpg";
case 2:
$foto="cartella2/".$imgs.".jpg";
break;
}
if(file_exists($foto))
echo CreaThumb($foto,500,500,"questo è il testo se esiste la foto");
else
echo CreaThumb("no_image.jpg",500,500,"questo è il testo se non trova la dirrectory");
spero di averti fatto capire come funge la funzione CreaThumb() ;)
per gestire posizione e grandezza del testo devi modificare i parametri di imagestring nella funzione CreaThumb:
http://it.php.net/manual/it/function.imagestring.php