Ensured that resized image won't ever get bigger than the maximum dimension