Python PIL | ImagePalette () method

This module has never been well documented. However, it hasn't changed since 2001, so it will probably be safe for you to read the source code and figure out the internals if you need to. The ImagePalette class has several methods, but they are all "experimental". 
ImagePalette.ImagePalette() Color palette for mapped palette images.

Syntax: PIL .ImagePalette.ImagePalette (mode = 'RGB', palette = None, size = 0)

Parameters:
mode - The mode to use for the Palette.
palette - An optional palette.
size - An optional palette size. If given, it cannot be equal to or greater than 256. Defaults to 0.

Return :: The ImagePalette object.

Image used:

 

  
# import Image module from PIL

from PIL import Image, ImagePalette

 
# open the image

im = Image. open (r "C: UsersSystem-PcDes ktoppython.png "

  
# ImagePalette

im1 = ImagePalette.ImagePalette (mode = 'RGB' , palette = None , size = 0 )

print (im1)

Output:

 PIL.ImagePalette.ImagePalette object at 0x000001930723FC50 

Another example: take another image with .JPG extension.

Image used:

< p>

  

  
# import Image module from PIL

from PIL import Image, ImagePalette

  
# open image

im = Image. open (r " C: UsersSystem-PcDesktopscene4. jpg "

  
# ImagePalette

im1 = ImagePalette. ImagePalette (mode < / code> = 'RGB' , palette = None , size = 0 )

print (im1)

Exit:

 PIL.ImagePalette.ImagePalette object at 0x000001B8808AFCC0 




Get Solution for free from DataCamp guru