code: def convertImagesToPIL(self, images, dither, nq=0):
          
  
          # Convert to PIL images
          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)
  
          # Convert to paletted PIL images
          images, images2 = images2, []
  
          # Adaptive PIL algorithm
          AD = Image.ADAPTIVE
          for im in images:
              im = im.convert('P', palette=AD, dither=dither)
              images2.append(im)
  
          # Done
          return images2
docs: convertImagesToPIL(images, nq=0)
  
          Convert images to Paletted PIL images, which can then be
          written to a single animaged GIF.