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

Python Methods and Functions

PIL — is a Python image library that provides the Python interpreter with image editing capabilities.




ImageChops.screen () method —

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

  Syntax:  ImageChops.screen (image1, image2)  Parameters:   image1  first image  image2  second image  Return Value:  An Image 

# This will import the Image and ImageChops modules

from PIL import Image, ImageChops

 
# Opening images

im =  Image. open (r "C: UsersAdminPicturesimages.png" )

im2 = Image. open (r "C: UsersAdminPicturesdownload.PNG " )

  
# overlay im and im2 images

im3 = ImageChops.screen (im, im2)

 
# show of the resulting image
im3.show ()

Output:




Method ImageChops. offset () —

This method returns a copy of the image where the data has been offset by the specified distances. The data is wrapped around the edges. If yoffset is omitted, it is assumed to be 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 orginal image

Output:





# This will import the Image and ImageChops modules

from PIL import Image, ImageChops

 
# Opening images

im = Image. open (r "C: UsersAdminPicturesimages.png" )

im2 = Image. open (r "C: UsersAdminPicturesdownload.PNG" )

  
# Here xoffset is given 100
# yoffset is automatically set to 100

im3 = ImageChops.offset (im, 140 )

  
# showing the resulting image
im3.show ()