'convertImagesToPIL(images, nq=0)
Convert images to Paletted PIL images, which can then be
written to a single animaged GIF.'

def convertImagesToPIL(self, images, dither, nq=0):

    images2 = []
    for im in images:
        if isinstance(im, Image.Image):
            images2.append(im)
        elif (np and isinstance(im, np.ndarray)):
            if ((im.ndim == 3) and (im.shape[2] == 3)):
                im = Image.fromarray(im, 'RGB')
            elif ((im.ndim == 3) and (im.shape[2] == 4)):
                im = Image.fromarray(im[:, :, :3], 'RGB')
            elif (im.ndim == 2):
                im = Image.fromarray(im, 'L')
            images2.append(im)
    (images, images2) = (images2, [])
    AD = Image.ADAPTIVE
    for im in images:
        im = im.convert('P', palette=AD, dither=dither)
        images2.append(im)
    return images2
