Codice PHP:
move_uploaded_file($_FILES["upfile"]["tmp_name"][0], "$upload_dir/$nome_file1")
or die($_FILES["upfile"]["error"][0]);
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);
Problema: per immagini che sono grandi dal punto di vista della risoluzione e del numero di colori usati il ridimensionamento non funziona: mi crea solo un'immagine nera... mi è stato detto che devo alzare il memory limit, ma non posso farlo... posso migliorare il mio codice?