ImagePalette Module in Pillow
Hello Programers! Continuing our topic on the pillow library we take a look at our next module that is the ImagePalette module.
Classes and Methods in ImagePalette module
- Imagepalette(): This is the only class in the ImagePalette module. It acts as a color palette for palette mapped images. It takes 3 parameters as input. The first parameter is a mode which defines the mode of the palette. The second parameter is a palette which is an optional parameter. If given then it must be a byte array, an array or list of ints between 0-255. And the last parameter is the size which is again an optional parameter and if given then it must not be equal to or greater than 256.
It consists of 5 methods and all of them marked as experimental. All the 5 experimental methods are as given below.
- getcolor(color): This method returns allocated palette entry when an RGB tuple is provided as an input.
- getdata(): This method returns the palette contents in a format suitable for low-level im.putpalette primitive.
- save(fp): This method takes a text file as an input and saves the palette.
- tobytes(): This method converts all the palette to bytes.
- tostring(): This method is a copy of tobytes method. Even this method converts palette to bytes.
NOTE: All the above methods are experimental methods.
Thank You guys for staying till the end. That’s it for this tutorial. We will meet in the next tutorial where I will be covering the ImagePath module from the pillow library.
Also read: Get the Basic image information with Pillow | Python
Leave a Reply