code: def get_pil_mode(value, alpha=False):
      
      name = {
          'GRAYSCALE': 'L',
          'BITMAP': '1',
          'DUOTONE': 'L',
          'INDEXED': 'P',
      }.get(value, value)
      if alpha and name in ('L', 'RGB'):
          name += 'A'
      return name
docs: Get PIL mode from ColorMode.