Codice PHP:
...
@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. Mi avete suggerito di alzare il memory limit a 64M ed ora va tutto bene. Tuttavia il provider mi chiede di ottimizzare il codice. Come posso fare?