Refactored the calculation of image sizes.