
PHP код:
$type=false;
if(isset($_GET["file"])&&!empty($_GET["file"])){
list($width, $height,$type) = getimagesize($_GET["file"]);
if(isset($_GET["width"],$_GET["height"])&&is_numeric($_GET["width"])&&is_numeric($_GET["height"])){
$newwidth=$_GET["width"];
$newheight=$_GET["height"];
}else{
$newwidth = 180;
$newheight = $height / ($width/180);
}
if($type)
switch ($type){
case 1:$source = imagecreatefromgif($_GET["file"]);
break;
case 2:$source = imagecreatefromjpeg($_GET["file"]);
break;
case 3:$source = imagecreatefrompng($_GET["file"]);
break;
}
if ($newwidth<=$width){
if($type==2)$thumb = imagecreatetruecolor($newwidth, $newheight);else
$thumb = imagecreate($newwidth, $newheight);
imagealphablending($thumb, false);
imagecopyresampled($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height);
}else $thumb=$source;
switch ($type){
case 1:
header("Content-type: image/gif");
imagegif($thumb);
break;
case 2:
header("Content-type: image/jpeg");
imagejpeg($thumb);
break;
case 3:
header("Content-type: image/png");
imagepng($thumb);
break;
}
}