questo è il codice...
class funzioni {
function ottimizza($file, $mime, $larghezza, $altezza) {
switch ($mime) {
case "image/pjpeg":
$ImgSorgente=imagecreatefromjpeg($file);
$array_sorgente = getimagesize($file);
break;
case "image/jpeg":
$ImgSorgente=imagecreatefromjpeg($file);
$array_sorgente = getimagesize($file);
break;
case "image/gif":
$ImgSorgente=imagecreatefromgif($file);
$array_sorgente = getimagesize($file);
break;
default:
$ImgSorgente=imagecreatetruecolor($larghezza, $altezza);
$bianco= imagecolorallocate($ImgSorgente, 255, 255, 255);
imagefill($ImgSorgente, $larghezza/2, $altezza/2, $bianco);
$array_sorgente = array($larghezza, $altezza);
break;
}
$imgDestinazione = imageCreateTrueColor($larghezza, $altezza);
imagecopyresampled($imgDestinazione, $ImgSorgente, 0, 0, 0, 0, $larghezza, $altezza, $array_sorgente[0], $array_sorgente[1]);
// mandiamo in output l'immagine e liberiamo la memoria
ob_start();
switch ($mime) {
case "image/pjpeg":
imagejpeg($imgDestinazione,'',100);
break;
case "image/jpeg":
imagejpeg($imgDestinazione,'',100);
break;
case "image/gif":
imagegif($imgDestinazione);
break;
default:
imagegif($imgDestinazione);
break;
}
$immagine = ob_get_contents();
ob_end_clean();
imagedestroy($imgDestinazione);
return $immagine;
}
}