def process_pil_image(image, quality=guetzli.DEFAULT_JPEG_QUALITY):
    """Generates an optimized JPEG from a PIL image. If the image has an alpha
    channel (transparency), it will be overlaid on a black background.

    :param image: the PIL image
    :param quality: the output JPEG quality (default 95)

    :returns: Optimized JPEG bytes
    :rtype: bytes

    :raises ImportError: PIL / Pillow cannot be imported.

    .. code:: python

        import pyguetzli
        from PIL import Image

        image = Image.open("./test/image.jpg")
        optimized_jpeg = pyguetzli.process_pil_image(image)
    """
    image_rgb = _to_pil_rgb_image(image)
    image_rgb_bytes = image_rgb.tobytes()
    return guetzli.process_rgb_bytes(
            image_rgb_bytes,
            *image.size,
            quality=quality
            )
Generates an optimized JPEG from a PIL image. If the image has an alpha
    channel (transparency), it will be overlaid on a black background.

    :param image: the PIL image
    :param quality: the output JPEG quality (default 95)

    :returns: Optimized JPEG bytes
    :rtype: bytes

    :raises ImportError: PIL / Pillow cannot be imported.

    .. code:: python

        import pyguetzli
        from PIL import Image

        image = Image.open("./test/image.jpg")
        optimized_jpeg = pyguetzli.process_pil_image(image)