I currently use this image dimension calculator within my image class
if (($width >= $maxwidth) and ($width > $height))
{
$newwidth = $maxwidth;
$newheight = $height * $maxwidth / $width;
}
else if (($height > $maxheight) and ($height > $width))
{
$newheight = $maxheight;
$newwidth = $width * $maxheight / $height;
}
else
{
$newwidth = $width;
$newheight = $height;
}
The problem is when an image is greater in height then width and over the maximum height it resizes the image to fit the aspect ratio of the maxheight.
This proves to be a problem when the aspect ratio causes the image to be higher than the maxwidth causing images on the site to expand out of their container.
How would I go about ensuring the image fits within a container size of x and y (maxwidth and maxheight)
thanks in advance