public function resizeFit(&$image, $newWidth, $newHeight)
{
$width = $image->getWidth();
$height = $image->getHeight();
$ratio = $width / $height;
// Try basing it on width first
$resizeWidth = $newWidth;
$resizeHeight = round($newWidth / $ratio);
if ($resizeWidth > $newWidth or $resizeHeight > $newHeight) {
// Oops, either with or height does not fit
// So base on height instead
$resizeHeight = $newHeight;
$resizeWidth = $newHeight * $ratio;
}
$this->_resize($image, $resizeWidth, $resizeHeight);
return $this;
}