PDA

View Full Version : PHP- problema ridimensionamento immagini


85michela85
22-04-2009, 13:23
Ciao a tutti!
ho elaborato questo codice che, dopo aver caricato su server l'immagine, la ridimensiona e ne crea un'anteprima:


...
@move_uploaded_file($_FILES["upfile"]["tmp_name"][0], "$upload_dir/$nome_file1")
or die("Non riesco a spostare il file");
list($width, $height, $type, $attr) = getimagesize("$upload_dir/$nome_file1");
if($width>450)
{
$newheight=ceil(450*$height/$width);
$thumb = imagecreatetruecolor(450,$newheight);
switch($type)
{
case 1:
$source = imagecreatefromgif("$upload_dir/$nome_file1");
imagecopyresized($thumb, $source, 0, 0, 0, 0, 450,$newheight, $width, $height);
imagegif($thumb, "$upload_dir/$nome_file1", 75);
break;
case 2:
$source = imagecreatefromjpeg("$upload_dir/$nome_file1");
imagecopyresized($thumb, $source, 0, 0, 0, 0, 450,$newheight, $width, $height);
imagejpeg($thumb, "$upload_dir/$nome_file1", 75);
break;
case 4:
$source = imagecreatefromwbmp("$upload_dir/$nome_file1");
imagecopyresized($thumb, $source, 0, 0, 0, 0, 450,$newheight, $width, $height);
imagewbmp($thumb, "$upload_dir/$nome_file1", 75);
break;
}
imagedestroy($thumb);
}
list($width, $height, $type, $attr) = getimagesize("$upload_dir/$nome_file1");
$newheight=ceil(150*$height/$width);
$thumb = imagecreatetruecolor(150,$newheight);
switch($type)
{
case 1:
$source = imagecreatefromgif("$upload_dir/$nome_file1");
imagecopyresized($thumb, $source, 0, 0, 0, 0, 150,$newheight, $width, $height);
imagegif($thumb, "$upload_dir/anteprima/$nome_file1", 75);
break;
case 2:
$source = imagecreatefromjpeg("$upload_dir/$nome_file1");
imagecopyresized($thumb, $source, 0, 0, 0, 0, 150,$newheight, $width, $height);
imagejpeg($thumb, "$upload_dir/anteprima/$nome_file1", 75);
break;
case 4:
$source = imagecreatefromwbmp("$upload_dir/$nome_file1");
imagecopyresized($thumb, $source, 0, 0, 0, 0, 150,$newheight, $width, $height);
imagewbmp($thumb, "$upload_dir/anteprima/$nome_file1", 75);
break;
default: copy("$upload_dir/$nome_file1","$upload_dir/anteprima/$nome_file1");
}
imagedestroy($thumb);
...


Qualche tempo fa si è verificato un problema con un'immagine che veniva caricata ma non ridimensionata.Ho fatto alzare il memory limit a 64M, ma ancora niente! Inoltre, il provider mi chiede di ottimizzare il codice perchè non può tenere un memory limit alto. Come posso fare?
Grazie del consiglio!!