mazey
    Preparing search index...

    Function calculateAspectRatio

    • Calculate the exact simplified aspect ratio of a width and height.

      The ratio is reduced using the greatest common divisor and returned with a lowercase x separator. The function does not approximate the result to a commonly named image or video ratio.

      Usage:

      import { calculateAspectRatio } from "mazey";

      const portraitRatio = calculateAspectRatio(900, 1200);
      const landscapeRatio = calculateAspectRatio(1920, 1080);

      console.log(portraitRatio);
      console.log(landscapeRatio);

      Output:

      3x4
      16x9
      

      Parameters

      • width: number

        Positive safe-integer width.

      • height: number

        Positive safe-integer height.

      Returns string

      The exact simplified aspect ratio in WxH form.

      If width or height is not a safe integer.

      If width or height is not greater than zero.