• Scales an image (or any content) to fit within a destination area while maintaining its aspect ratio.

    The function calculates the scaling factor by determining the minimum scale factor between the destination width and height based on the source's aspect ratio. It then clamps the result to be within the specified minimum and maximum scale factors.

    Parameters

    • sourceWidth: number

      The width of the source content (e.g., image width).

    • sourceHeight: number

      The height of the source content (e.g., image height).

    • destWidth: number

      The width of the destination area to fit the content within.

    • destHeight: number

      The height of the destination area to fit the content within.

    • Optionalmin: number

      The minimum scale factor. Defaults to 0.

    • Optionalmax: number

      The maximum scale factor. Defaults to Infinity.

    Returns number

    The scale factor to apply to the source content to fit it within the destination area.