if?($_POST)?{
????
//?No?image?
????
if?(empty($_FILES['image'])?OR?$_FILES['image']['error']?!=?UPLOAD_ERR_OK)?{
????????die?(
'Invalid?image?uploaded.??Please?go?back?and?try?again.');
????}

????
$imagepath?=?$_FILES['image']['tmp_name'];

????
//?Load?image
????
$image?=?open_image($imagepath);

????if?(
$image?==?false)?{
????????die?(
'You?uploaded?an?invalid?image.?Please?go?back?and?try?again.');
????}

????
//?Get?original?width?and?height
????
$width?=?imagesx($image);
????
$height?=?imagesy($image);

????
//?Percentage?
????
if?(!empty($_POST['percent'])?AND?is_numeric($_POST['percent']))?{
????????
$percent?=?floatval($_POST['percent']);
????????
$percent?=?$percent/100;

????????
$new_width?=?$width?*?$percent;
????????
$new_height?=?$height?*?$percent;

????
//?New?width??Calculate?new?height
????
}?elseif?(!empty($_POST['new_width'])?AND?is_numeric($_POST['new_width']))?{
????????
$new_width?=?floatval($_POST['new_width']);
????????
$new_height?=?$height?*?($new_width/$width);

????
//?New?height??Calculate?new?width
????
}?elseif?(!empty($_POST['new_height'])?AND?is_numeric($_POST['new_height']))?{
????????
$new_height?=?floatval($_POST['new_height']);
????????
$new_width?=?$width?*?($new_height/$height);

????
//?New?height?and?new?width
????
}?elseif?(!empty($_POST['height'])?AND?is_numeric($_POST['height'])?AND?!empty($_POST['width'])?AND?is_numeric($_POST['width']))?{
????????
$new_height?=?floatval($_POST['height']);
????????
$new_width?=?floatval($_POST['width']);
????}?else?{
????????die?(
'You?didn\'t?specify?any?resizing?options.');
????}????

????
//?Resample
????
$image_resized?=?imagecreatetruecolor($new_width,?$new_height);
????
imagecopyresampled($image_resized,?$image,?0,?0,?0,?0,?$new_width,?$new_height,?$width,?$height);

????
//?Display?resized?image
????
header('Content-type:?image/jpeg');
????
imagejpeg($image_resized);
????die();

}

//?Display?the?upload?form:
?>

????
????????Image?Resizer

????
????????th?{?text-align:?right;?}
????

????

????
????????
????????
????????????
????????????????
????????????????
????????????

????????????
????????????????
????????????????
????????????

????????????
????????????????
????????????????
????????????

????????????
????????????????
????????????????
????????????

????????????
????????????????
????????????????
????????????


????????????
????????
????



function?open_image?($file)?{
????
#?JPEG:
????
$im?=?@imagecreatefromjpeg($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?GIF:
????
$im?=?@imagecreatefromgif($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?PNG:
????
$im?=?@imagecreatefrompng($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?GD?File:
????
$im?=?@imagecreatefromgd($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?GD2?File:
????
$im?=?@imagecreatefromgd2($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?WBMP:
????
$im?=?@imagecreatefromwbmp($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?XBM:
????
$im?=?@imagecreatefromxbm($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?XPM:
????
$im?=?@imagecreatefromxpm($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?Try?and?load?from?string:
????
$im?=?@imagecreatefromstring(file_get_contents($file));
????if?(
$im?!==?false)?{?return?$im;?}

????return?
false;
}
?>
Image:
Resize?to:?%?(percentage)
OR?new?width:??pixels?(height?will?be?calculated?automatically)
OR?new?height:??pixels?(width?will?be?calculated?automatically)
OR?new?height?and?new?width:?
????????????????????
????????????????????????
????????????????????????
????????????????????
width:?pixels
height:?pixels

????????????????