from PIL import Image
import base64
import io


def base64ToPilImg(base64ImgString):
    """Converts a base64 encoded image to PIL image 

    Arguments:
        base64ImgString {string} -- Encoded base64 image string

    Returns:
        PIL -- PIL image
    """
    if base64ImgString.startswith('b\''):
        base64ImgString = base64ImgString[2:-1]
    base64Img   =  base64ImgString.encode('utf-8')
    decoded_img = base64.b64decode(base64Img)
    img_buffer  = io.BytesIO(decoded_img)
    pil_img = Image.open(img_buffer).convert('RGB')
    return pil_img