Python PIL | ImagePalette() Method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImagePalette module contains a class of the same name to represent the color palette of palette mapped images.

This module was never well-documented. It hasn’t changed since 2001, though, so it’s probably safe for you to read the source code and puzzle out the internals if you need to. The ImagePalette class has several methods, but they are all “experimental.”
The ImagePalette.ImagePalette() Color palette for palette mapped 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

   
  
# importing Image module from PIL package 
from PIL import Image, ImagePalette
  
# opening a  image 
im = Image.open(r"C:\Users\System-Pc\Desktop\python.png"
  
# ImagePalette
im1 = ImagePalette.ImagePalette(mode ='RGB', palette = None, size = 0)
print(im1)

chevron_right


Output:

PIL.ImagePalette.ImagePalette object at 0x000001930723FC50

Another Example: take another image with .JPG extension.

Image Used:

filter_none

edit
close

play_arrow

link
brightness_4
code

   
  
# importing Image module from PIL package 
from PIL import Image, ImagePalette
  
# opening a  image 
im = Image.open(r"C:\Users\System-Pc\Desktop\scene4.jpg"
  
# ImagePalette
im1 = ImagePalette.ImagePalette(mode ='RGB', palette = None, size = 0)
print(im1)

chevron_right


Output:

PIL.ImagePalette.ImagePalette object at 0x000001B8808AFCC0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.