def rescale_image_by_path(path: str, height: int, width: int):
    """
    Rescales an image to the specified height and width and saves it back to the original path.

    Args:
        path (str): The file path of the image.
        height (int): The target height of the image.
        width (int): The target width of the image.
    """
    try:
        # read image
        image = Image.open(path)

        # check if image is valid
        if image is None:
            raise ValueError("The image is invalid or empty.")

        # resize image
        resize_transform = transforms.Resize((width, height))
        resized_image = resize_transform(image)

        # save resized image back to the original path
        resized_image.save(path)

    except Exception as e:
        print(f"Error rescaling image: {e}")

    Rescales an image to the specified height and width and saves it back to the original path.

    Args:
        path (str): The file path of the image.
        height (int): The target height of the image.
        width (int): The target width of the image.
    
opensora/datasets/utils.py