questo è il mio script per ridimensionare le immagini, spero ti possa essere utile, basta fargli piccole modifiche
Codice PHP:
do {
// Ottengo le informazioni sull'immagine originale
list($width, $height, $type, $attr) = getimagesize($immagine);
// Controllo che il file sia in uno dei formati 1. GIF, 2. JPG o 3. PNG
if ($type!=2) { $avatar = $immagine;
break; }
// Controllo che il file non superi i 300 KB
if ($_FILES['image']['size'] > 307200) {
$avatar = $immagine; break; }
// Creo la versione 470*y dell'immagine (thumbnail)
$y = ( 470 * $height ) / $width;
if( $y < 500 ) {
$thumb = imagecreatetruecolor(470, $y);
$source = imagecreatefromjpeg($immagine);
imagecopyresized($thumb, $source, 0, 0, 0, 0, 470, $y, $width, $height);
} else {
$thumb = imagecreatetruecolor(470, 290);
$source = imagecreatefromjpeg($immagine);
imagecopyresized($thumb, $source, 0, 0, 0, 0, 470, 290, $width, $height); }
// Salvo l'immagine ridimensionata
imagejpeg($thumb, './uploadimg/' . $timestamp . '.jpg', 90);
} while (false);