def img_2_b64(image: ImageFile, format: str = "JPEG") -> str:
    """
    Convert a PIL.Image to a base64 encoded image string.

    Args:
        image (ImageFile): The PIL Image object to be converted.
        format (str, optional): The image format to save as. Defaults to "JPEG".

    Returns:
        str: A base64 encoded string representation of the image.

    """
    buff = BytesIO()
    image.save(buff, format=format)
    return cast(str, base64.b64encode(buff.getvalue()))

    Convert a PIL.Image to a base64 encoded image string.

    Args:
        image (ImageFile): The PIL Image object to be converted.
        format (str, optional): The image format to save as. Defaults to "JPEG".

    Returns:
        str: A base64 encoded string representation of the image.

    
llama-index-core/llama_index/core/img_utils.py