def rotate_pillow_image(pillow_image, orientation):
    """Return a copy of a Pillow image with modified orientation.

    If orientation is not changed, return the same image.

    """
    image_format = pillow_image.format
    if orientation == 'from-image':
        if 'exif' in pillow_image.info:
            pillow_image = ImageOps.exif_transpose(pillow_image)
    elif orientation != 'none':
        angle, flip = orientation
        if angle > 0:
            rotation = getattr(Image.Transpose, f'ROTATE_{angle}')
            pillow_image = pillow_image.transpose(rotation)
        if flip:
            pillow_image = pillow_image.transpose(
                Image.Transpose.FLIP_LEFT_RIGHT)

    # Keep image format as it is discarded by transposition
    pillow_image.format = image_format
    return pillow_image
Return a copy of a Pillow image with modified orientation.

If orientation is not changed, return the same image.
weasyprint/images.py