• Searches for the smallest (?) suitable image from the sizes array.

    Or more precise, it returns: – if no suitable sizes (>= minWidth И >= minHeight): the biggest from all sizes; – there are any suitable (>= minWidth И >= minHeight): the smallest of the matching sizes;

    Returns null only in case of an empty/invalid array. The returned size can be smaller than minWidth or minHeight.

    The function doesn't take into about the retina screen (window.devicePixelRatio), so you have to calculate the right width/height from the outside to support it.

    WARN:

    • does not reckon for letter-sizes (PhotosPhotoSizesType).
    • does not know how to search for the "nearest" size, or the maximum image (there is a hack with the Infinity pass).

    Parameters

    • sizes: PhotoSizeLike[]
    • minWidth: number
    • minHeight: null | number = null

    Returns PhotoSize | null

    getPhotoSize([{ width: 1, height: 1 }, { width: 3, height: 3 }], 1) // => 1,1
    getPhotoSize([{ width: 1, height: 1 }, { width: 3, height: 3 }], 2) // => 3,3
    getPhotoSize([{ width: 1, height: 1 }, { width: 3, height: 3 }], 4) // => 3,3

    See more examples in tests