<?php
if (isset($_REQUEST['f'])) {
$filename = @$_REQUEST['f'];
if (isset($_REQUEST['h']))
$h = $_REQUEST['h'];
else
$h = 0;
if (isset($_REQUEST['w']))
$w = $_REQUEST['w'];
else
$w = 0;
resizeimg($filename, $w, $h);
}
function resizeimg($filename, $w, $h) {
$flag = true;
$ration = $w/$h;
$size_img = getimagesize($filename);
if (($size_img[0]<$w) && ($size_img[1]<$h))
$flag = false;
$src_ratio = $size_img[0]/$size_img[1];
if ($flag) {
if ($ration<$src_ratio)
$h = intval($w/$src_ratio);
else
$w = intval($h*$src_ratio);
$dest_img = imagecreatetruecolor($w, $h);
if ($size_img[2]==2) $src_img = imagecreatefromjpeg($filename);
elseif ($size_img[2]==1) $src_img = imagecreatefromgif($filename);
elseif ($size_img[2]==3) $src_img = imagecreatefrompng($filename);
if (!imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $w, $h, $size_img[0], $size_img[1]))
return false;
} else {
$dest_img = imagecreatefromjpeg($filename);
}
$path_parts = pathinfo($filename);
if ($path_parts["extension"]=="jpg") {
header ("Content-type: image/jpeg");
imagejpeg($dest_img);
} elseif ($path_parts["extension"]=="gif") {
header ("Content-type: image/gif");
imagegif($dest_img);
} elseif ($path_parts["extension"]=="png") {
header ("Content-type: image/png");
imagepng($dest_img);
}
imagedestroy($dest_img);
imagedestroy($src_img);
return true;
}
?>