function uploadResizedImage(
$sourceImagePathname, $targetImagePath, $imageType, $maximumDimension)
{
$resultSave = false;
list($width, $height) = getimagesize($sourceImagePathname);
if(($maximumDimension >= $width) && ($maximumDimension >= $height)) {
$resultSave = copy($sourceImagePathname, $targetImagePath);
}
else {
$sourceImage = @createImageFactory($sourceImagePathname, $imageType);
if($width > $height) {
$newWidth = round($maximumDimension);
$newHeight = round($height * ($newWidth / $width));
}
else {
$newHeight = round($maximumDimension);
$newWidth = round($width * ($newHeight / $height));
}
$targetImage = createNewImage($newWidth, $newHeight, $imageType);
$resultResize = imagecopyresampled($targetImage, $sourceImage,
0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if($resultResize) {
$resultSave = saveImage($targetImage, $targetImagePath, $imageType);
}
}
return $resultSave;
}