Ciao,
ho questo script che mi fa il resize delle immagini che carico.
Codice PHP:
$width_big = 750;
$size_big = getimagesize($file_tmp);
if ($size_big[0]>$width_big) {
$height_big = $size_big[1]*($width_big/$size_big[0]);
$source_big = imagecreatefromjpeg($file_tmp);
$img_big = imagecreatetruecolor($width_big, $height_big);
imagecopyresampled($img_big,$source_big,0,0,0,0,$width_big, $height_big, $size_big[0], $size_big[1]);
$ext_name = substr(strrchr($file_name, "."), 1);
$imagePath_big = md5(rand() * time()) . ".$ext_name";
// Salvo l'immagine ridimensionata
imagejpeg($img_big, SRV_ROOT . 'images/product/'.$imagePath_big, 75);
imagedestroy($source_big);
imagedestroy($img_big);
}
Il problema è che se l'immagine $size_big[0] è minore di $width_big non fa nulla, non esegue l'upload.
Allora ho aggiunto un else all' if
Codice PHP:
} else { $img_big = $size_big;
imagejpeg($img_big, SRV_ROOT . 'images/product/'.$imagePath_big, 75);
imagedestroy($source_big); imagedestroy($img_big); }
ma non funziona ugualmente