Python PIL ImagePalette() method
Python PIL ImagePalette() Method
PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The ImagePalette module contains a class of the same name that represents the palette of a palette-mapped image.
This module has never been well documented. However, it has remained unchanged since 2001, so you can read the source code to understand what’s going on internally if you need to. The ImagePalette class has several methods, but they are all “experimental.”
ImagePalette.ImagePalette() Returns the palette of a palette-mapped image.
Syntax: PIL.ImagePalette.ImagePalette(mode='RGB', palette=None, size=0)
Parameters:
mode – The mode to use for the palette.
palette – An optional palette.
size – The optional palette size. If given, it cannot be equal to or greater than 256. Defaults to 0.
Returns: The image palette object.
Images used:
# importing Image module from PIL package
from PIL import Image, ImagePalette
# opening a image
im = Image.open(r"C:UsersSystem-PcDesktoppython.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 a .JPG extension.
Images used:
# importing Image module from PIL package
from PIL import Image, ImagePalette
# opening a image
im = Image.open(r"C:UsersSystem-PcDesktopscene4.jpg")
#ImagePalette
im1 = ImagePalette.ImagePalette(mode ='RGB', palette = None, size = 0)
print(im1)
Output:
PIL.ImagePalette.ImagePalette object at 0x000001B8808AFCC0