public static void Main()
double imageWidth = 1920;
double imageHeight = 1080;
double aspectRatio = imageWidth / imageHeight;
double newImageWidth = 0;
double newImageHeight = 0;
double diffWidth = imageWidth- minWidth;
double diffHeight = imageHeight - minHeight;
if (diffWidth > 0 && diffHeight > 0)
if (diffWidth < diffHeight)
newImageWidth = Math.Round(minHeight * aspectRatio);
newImageHeight = minHeight;
if (newImageWidth < minWidth)
newImageWidth = minWidth;
newImageHeight = Math.Round(minWidth * (1/aspectRatio));
newImageWidth = minWidth;
newImageHeight = Math.Round(minWidth * (1/aspectRatio));
if (newImageHeight < minHeight)
newImageWidth = Math.Round(minHeight * aspectRatio);
newImageHeight = minHeight;
newImageWidth = imageWidth;
newImageHeight = imageHeight;
double newAspectRatio = newImageWidth / newImageHeight;
Console.WriteLine("Old: {0}/{1} = {2}, new: {3}/{4} = {5}",
imageWidth, imageHeight, aspectRatio, newImageWidth, newImageHeight, newAspectRatio);