def rotate_resize_image(
        array: np.ndarray,
        angle: float = 0.0,
        scale_ratio: float = 1.0,
        dx: float = 0.0,
        dy: float = 0.0,
        use_white_bg: Optional[bool] = False,
    ) -> np.ndarray:
        """
        Rotate and resize an image while optionally setting excess border to white.

        Args:
            array (np.ndarray): The input image.
            angle (float, optional): The rotation angle in degrees (default is 0.0).
            scale_ratio (float, optional): The scaling ratio (default is 1.0).
            dx (float, optional): The translation along the x-axis (default is 0.0).
            dy (float, optional): The translation along the y-axis (default is 0.0).
            use_white_bg (bool, optional): Whether to set the excess border to white (default is False).

        Returns:
            np.ndarray: The rotated and resized image.
        """
        height, width = array.shape[:2]
        image_center = (width / 2, height / 2)

        rotation_mat = cv2.getRotationMatrix2D(image_center, angle, scale_ratio)

        # Calculate the size of the new image to accommodate the rotated image
        radians = math.radians(angle)
        sin = math.sin(radians)
        cos = math.cos(radians)
        bound_w = int((height * abs(sin)) + (width * abs(cos)))
        bound_h = int((height * abs(cos)) + (width * abs(sin)))

        # Adjust the rotation matrix to translate to the center of the new image
        rotation_mat[0, 2] += (bound_w - width) / 2
        rotation_mat[1, 2] += (bound_h - height) / 2

        rotated_mat = cv2.warpAffine(array, rotation_mat, (bound_w, bound_h))

        # Apply the final padding (dx and dy)
        pad_left = max(0, int(dx))
        pad_right = max(0, -int(dx))
        pad_top = max(0, int(dy))
        pad_down = max(0, -int(dy))
        rotated_mat = cv2.copyMakeBorder(rotated_mat, pad_top, pad_down, pad_left, pad_right, cv2.BORDER_CONSTANT, value=0)

        if use_white_bg:
            # Create a white background with the same size
            white_bg = np.zeros_like(rotated_mat)
            white_bg.fill(255)  # Set the background to white

            # Combine the rotated image and the white background using a mask
            mask = rotated_mat == 0
            rotated_mat = np.where(mask, white_bg, rotated_mat)

        return rotated_mat

        Rotate and resize an image while optionally setting excess border to white.

        Args:
            array (np.ndarray): The input image.
            angle (float, optional): The rotation angle in degrees (default is 0.0).
            scale_ratio (float, optional): The scaling ratio (default is 1.0).
            dx (float, optional): The translation along the x-axis (default is 0.0).
            dy (float, optional): The translation along the y-axis (default is 0.0).
            use_white_bg (bool, optional): Whether to set the excess border to white (default is False).

        Returns:
            np.ndarray: The rotated and resized image.
        
scripts/easyphoto_utils/tryon_utils.py