if($_SERVER['REQUEST_METHOD'] == ‘POST’) {
if($_FILES['image']) {
preg_match(‘/.([A-Za-z]+?)$/’, $_FILES['image']['name'], $matches);
$matches[1] = strtolower($matches[1]);
if($matches[1] == ‘png’ && function_exists(‘imagecreatefrompng’) || $matches[1] == ‘jpg’ && function_exists(‘imagecreatefromjpeg’) || $matches[1] == ‘jpeg’ && function_exists(‘imagecreatefromjpeg’) || $matches[1] == ‘gif’ && function_exists(‘imagecreatefromgif’) || $matches[1] == ‘bmp’ && function_exists(‘imagecreatefromwbmp’)) {
list($owidth, $oheight) = getimagesize($_FILES['image']['tmp_name']);
if($_POST['resizeby'] == ‘height’) {
$nheight = ($_POST['size']>1)?$_POST['size']:600;
$nwidth = $nheight / $oheight * $owidth;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
else {
$nwidth = ($_POST['size']>1)?$_POST['size']:800;
$nheight = $nwidth / $owidth * $oheight;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
if($matches[1] == ‘png’)
$original = imagecreatefrompng($_FILES['image']['tmp_name']);
if($matches[1] == ‘jpg’ || $matches[1] == ‘jpeg’)
$original = imagecreatefromjpeg($_FILES['image']['tmp_name']);
if($matches[1] == ‘gif’)
$original = imagecreatefromgif($_FILES['image']['tmp_name']);
if($matches[1] == ‘bmp’)
$original = imagecreatefromwbmp($_FILES['image']['tmp_name']);
imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);
header(‘Content-Disposition: attachment; filename=”‘.$_FILES['image']['name'].’”‘);
header(‘Content-type: image/’.(($matches[1] == ‘jpg’)?’jpeg’:$matches[1]));
if($matches[1] == ‘png’)
imagepng($resized);
if($matches[1] == ‘jpg’ || $matches[1] == ‘jpeg’)
imagejpeg($resized);
if($matches[1] == ‘gif’)
imagegif($resized);
if($matches[1] == ‘bmpg’)
imagewbmp($resized);
exit();
} else
$error = ‘File type not supported!’;
} else
$error = ‘No image uploaded!’;
}
?> if($error)
print ‘
‘.$error.’
‘;
?>
Powered by DXL dev’.