<?php
public function getImageSizeKeepAspectRatio( $imageUrl, $maxWidth, $maxHeight)
{
$imageDimensions = getimagesize($imageUrl);
$imageWidth = $imageDimensions[0];
$imageHeight = $imageDimensions[1];
$imageSize['width'] = $imageWidth;
$imageSize['height'] = $imageHeight;
if($imageWidth > $maxWidth || $imageHeight > $maxHeight)
{
if ( $imageWidth > $imageHeight ) {
$imageSize['height'] = floor(($imageHeight/$imageWidth)*$maxWidth);
$imageSize['width'] = $maxWidth;
} else {
$imageSize['width'] = floor(($imageWidth/$imageHeight)*$maxHeight);
$imageSize['height'] = $maxHeight;
}
}
return $imageSize;
}
?>