Thursday, July 4, 2024
HomeLanguagesPythonPython PIL | ImageChops.screen() and ImageChops.offset() method

Python PIL | ImageChops.screen() and ImageChops.offset() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities.
 

ImageChops.screen() method –

This method is used to superimpose two inverted images on top of each other.
 

Syntax: ImageChops.screen(image1, image2)

Parameters:
image1 first image
image2 second image

Return Value: An Image

 

Python3




# This will import Image and ImageChops modules
from PIL import Image, ImageChops
 
# Opening Images
im = Image.open(r"C:\Users\Admin\Pictures\images.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\download.PNG")
 
# superimposing images im and im2
im3 = ImageChops.screen(im, im2)
 
# showing resultant image
im3.show()


Output: 
 

 

ImageChops.offset() method –

This method returns a copy of the image where data has been offset by the given distances. Data wraps around the edges. If yoffset is omitted, it is assumed to be equal to xoffset.
 

Syntax: ImageChops.offset(image1, xoffset, yoffset = None)
Parameters: 
image: It is the image on which offset is provided 
xoffset: the horizontal distance 
yoffset: it is the vertical distance, if omitted both distance are set to same.
Return value: Copy of the original image 
 

 

Python3




# This will import Image and ImageChops modules
from PIL import Image, ImageChops
 
# Opening Images
im = Image.open(r"C:\Users\Admin\Pictures\images.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\download.PNG")
 
# Here, xoffset is given 100
# yoffset will automatically set to 100
im3 = ImageChops.offset(im, 140)
 
# showing resultant image
im3.show()


Output: 
 

 

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments