Ciao, ho scritto questo script per ridimensionare le immagini, ma ho due problemi:
1. se l' immagine è inferiore a $grande giustamente me la lascia della dimensione reale, ma la proporzione della foto è sballata, come posso risolvere il problema??
2. se inserisco un immagine in png con il fondo trasparente, non me la salva con il fondo trasparente ma con il fondo nero.
Potreste dare un occhiata a questo codice e farci una correzione??
Grazie mille
Codice PHP:
$grande = 550;
$filename = $immagine;
// Set a maximum height and width
$width = $grande;
$height = $grande;
// Content type
// header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width_orig > $width OR $height_orig > $height){
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}else{
$width = $width_orig;
$height = $width_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$formato = getimagesize($filename);
if( $formato[2] == 2 ){$image = imagecreatefromjpeg($filename);}
elseif( $formato[2] == 1 ){$image = imagecreatefromgif($filename);}
elseif( $formato[2] == 3 ){$image = imagecreatefrompng($filename);}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
if( $formato[2] == 2 ){imagejpeg($image_p, "imgb/articoli/$id/$numero_img.jpg", 100);}
elseif( $formato[2] == 1 ){imagegif($image_p, "imgb/articoli/$id/$numero_img.gif");}
elseif( $formato[2] == 3 ){imagepng($image_p, "imgb/articoli/$id/$numero_img.png");}