Codice PHP:
<?
$file = $_GET['img'];
$resize = $_GET['w'];
$altez = $_GET['h'];
$pezzi=explode('/', $file);
$nomeF=$pezzi[count($pezzi)-1];
$cosa = getimagesize($file);
$width = ($resize < $cosa[0]) ? $resize : $cosa[0];
$alte = (!$altez) ? ceil(($cosa[1] * $width)/$cosa[0])+1 : $altez;
$min = imagecreatetruecolor($width, $alte);
switch($cosa['mime']){
case 'image/png':
header('Content-Disposition: attachment; filename="'.$nomeF.'"');
$im = imagecreatefrompng($file);
imagealphablending($min, false);
imagecopyresized($min, $im, 0, 0, 0, 0, $width, $alte, imageSx($im), imageSy($im));
imagesavealpha($min, true);
imagepng($min,'',8,PNG_ALL_FILTERS);
break;
case 'image/gif':
header('Content-Disposition: attachment; filename="'.$nomeF.'"');
$im = imagecreatefromgif($file);
imagealphablending($min, false);
$colorTransparent = imagecolorallocatealpha($min, 0, 0, 0, 127);
imagefill($min, 0, 0, $colorTransparent);
imagecopyresized($min, $im, 0, 0, 0, 0, $width, $alte, imageSx($im), imageSy($im));
imagesavealpha($min, true);
imagepng($min,'',8,PNG_ALL_FILTERS);
break;
case 'image/jpeg':
case 'image/jpg':
header('Content-Disposition: attachment; filename="'.$nomeF.'"');
$im = imagecreatefromjpeg($file);
imagecopyresized($min, $im, 0, 0, 0, 0, $width, $alte, imageSx($im), imageSy($im));
imagejpeg($min,'',85);
break;
}
imagedestroy($min);
?>
buon divertimento