class_docstr: Class that for helping write the animated GIF file. This is based on
  code from images2gif.py (part of visvis). The version here is modified
  to allow streamed writing.
class_docstr_tok: ["Class","that","for","helping","write","the","animated","GIF","file",".","This","is","based","on","code","from","images2gif.py","(","part","of","visvis",")",".","The","version","here","is","modified","to","allow","streamed","writing","."]
docstr: Convert image to Paletted PIL image.
  
  PIL used to not do a very good job at quantization, but I guess
  this has improved a lot (at least in Pillow). I don't think we need
  neuqant (and we can add it later if we really want).
docstr_tok: ["Convert","image","to","Paletted","PIL","image",".","PIL","used","to","not","do","a","very","good","job","at","quantization",",","but","I","guess","this","has","improved","a","lot","(","at","least","in","Pillow",")",".","I","do","n't","think","we","need","neuqant","(","and","we","can","add","it","later","if","we","really","want",")","."]
code: def converToPIL(self, im, quantizer, palette_size=256):
      """Convert image to Paletted PIL image.
  
      PIL used to not do a very good job at quantization, but I guess
      this has improved a lot (at least in Pillow). I don't think we need
      neuqant (and we can add it later if we really want).
      """
  
      im_pil = ndarray_to_pil(im, "gif")
  
      if quantizer in ("nq", "neuquant"):
          # NeuQuant algorithm
          nq_samplefac = 10  # 10 seems good in general
          im_pil = im_pil.convert("RGBA")  # NQ assumes RGBA
          nqInstance = NeuQuant(im_pil, nq_samplefac)  # Learn colors
          im_pil = nqInstance.quantize(im_pil, colors=palette_size)
      elif quantizer in (0, 1, 2):
          # Adaptive PIL algorithm
          if quantizer == 2:
              im_pil = im_pil.convert("RGBA")
          else:
              im_pil = im_pil.convert("RGB")
          im_pil = im_pil.quantize(
              colors=palette_size, method=quantizer
          )
      else:
          raise ValueError(
              "Invalid value for quantizer: %r" % quantizer
          )
      return im_pil
  
file_path: imageio/imageio/plugins/pillowmulti.py
imports: import logging
  import numpy
  from .pillow_legacy import PillowFormat, image_as_uint, ndarray_to_pil
label_desc: Use image node_id 11 for calling the GifWriter obj's underlying member method code with example usage: obj.converToPIL(im, quantizer, palette_size) and returns: im_pil