Python PIL putalpha() method
Python PIL putalpha() Method
PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The image module provides a class of the same name to represent a PIL image. The module also provides factory functions, including functions for loading images from files and creating new images.
Image.putalpha() Adds or replaces the alpha layer in this image. If the image does not have an alpha layer, it will be converted to “LA” or “RGBA”. The new layer must be “L” or “1”.
Syntax: Image.putalpha(alpha)
Parameters:
alpha – The new alpha layer. This can be an image of “L” or “1” with the same size as the image, or an integer or other color value.
Return: An image object.
Images used:
# importing Image class from PIL package
from PIL import Image
#creating an object
im = Image.open(r"C:UsersSystem-PcDesktoplion.png")
# using putalpha method
im.putalpha(1)
# show image object
im.show()
Output:
Another example: Using another image.
Images used:
# importing Image class from PIL package
from PIL import Image
#creating an object
im = Image.open(r"C:UsersSystem-PcDesktopbutter.png")
# using putalpha method
im.putalpha(1)
# show image object
im.show()
Output: