def _to_pil_rgb_image(image):
    """Returns an PIL Image converted to the RGB color space. If the image has
    an alpha channel (transparency), it will be overlaid on a black background.

    :param image: the PIL image to convert

    :returns: The input image if it was already in RGB mode, or a new RGB image
              if converted.

    :raises ImportError: PIL / Pillow cannot be imported.
    """
    if image.mode == 'RGB':
        return image
    from PIL import Image
    image.load()
    rgb_image = Image.new('RGB', image.size, (0, 0, 0))
    mask = None
    if image.mode == 'RGBA':
        mask = image.split()[3]
    rgb_image.paste(image, mask=mask)
    return rgb_image
