def get_resize_crop_region_for_grid(src, tgt_width, tgt_height):
    """
    This function calculates the resize and crop region for an image to fit a target width and height while preserving
    the aspect ratio.

    Parameters:
    - src (tuple): A tuple containing the source image's height (h) and width (w).
    - tgt_width (int): The target width to resize the image.
    - tgt_height (int): The target height to resize the image.

    Returns:
    - tuple: Two tuples representing the crop region:
        1. The top-left coordinates of the crop region.
        2. The bottom-right coordinates of the crop region.
    """

    tw = tgt_width
    th = tgt_height
    h, w = src
    r = h / w
    if r > (th / tw):
        resize_height = th
        resize_width = int(round(th / h * w))
    else:
        resize_width = tw
        resize_height = int(round(tw / w * h))

    crop_top = int(round((th - resize_height) / 2.0))
    crop_left = int(round((tw - resize_width) / 2.0))

    return (crop_top, crop_left), (crop_top + resize_height, crop_left + resize_width)

    This function calculates the resize and crop region for an image to fit a target width and height while preserving
    the aspect ratio.

    Parameters:
    - src (tuple): A tuple containing the source image's height (h) and width (w).
    - tgt_width (int): The target width to resize the image.
    - tgt_height (int): The target height to resize the image.

    Returns:
    - tuple: Two tuples representing the crop region:
        1. The top-left coordinates of the crop region.
        2. The bottom-right coordinates of the crop region.
    
src/diffusers/pipelines/consisid/pipeline_consisid.py