private function getSizeByAuto($newWidth, $newHeight, $width, $height) { if ($height < $width) { $optimalWidth = $newWidth; $optimalHeight = resizeImageHelper::getSizeByFixedWidth($newWidth, $width, $height); } elseif ($height > $width) { $optimalWidth = resizeImageHelper::getSizeByFixedHeight($newHeight, $width, $height); $optimalHeight = $newHeight; } else { if ($newHeight < $newWidth) { $optimalWidth = $newWidth; $optimalHeight = resizeImageHelper::getSizeByFixedWidth($newWidth, $width, $height); } else { if ($newHeight > $newWidth) { $optimalWidth = resizeImageHelper::getSizeByFixedHeight($newHeight, $width, $height); $optimalHeight = $newHeight; } else { //Sqaure being resized to a square $optimalWidth = $newWidth; $optimalHeight = $newHeight; } } } return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight); }