Determine if an image is more or less landscape (or portrait) than given dimensions

Here’s a nifty c# extension method I wrote to determine how an image should be resized and/or cropped to fit within certain dimensions.

If you divide a rectangle’s width by it’s height you get a number representing the aspect. If both sides are equal you get 1. If the width is greater than the height you get a number that is more than 1, and if the height is greater you get a number less than 1.

public static bool IsMoreLandscapeThan(this Size size, Size compareSize){
  float aspect = (float)size.Width / (float)size.Height;
  float compareAspect = (float)compareSize.Width / (float)compareSize.Height;
  return aspect > compareAspect;
}

Here’s how to use it:

if (originalImage.Size.IsMoreLandscapeThan(newSize))
{
  //Do something
}