Python PIL | ImageGrab.grab() method

PIL is the Python Imaging Library which provides the python interpreter with image editing
capabilities. The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory.

PIL.ImageGrab.grab() method takes a snapshot of the screen. The pixels inside the bounding box are returned as an “RGB” image on Windows or “RGBA” on macOS. If the bounding box is omitted, the entire screen is copied.

Syntax: PIL.ImageGrab.garb(bbox=None)

parameters: 
bbox: What region to copy. Default is the entire screen.

Returns: An image
filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing Image and ImageGrab module from PIL package 
from PIL import Image, ImageGrab
    
# creating an image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
    
# using the grab method
im2 = ImageGrab.grab(bbox = None)
    
im2.show()

chevron_right


Output:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing Image and ImageGrab module from PIL package 
from PIL import Image, ImageGrab
    
# creating an image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
    
# using the grab method
im2 = ImageGrab.grab(bbox =(0, 0, 300, 300))
    
im2.show()

chevron_right


Output:

Different values of bbox can be used for different screen sizes.



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.



Improved By : nidhi_biet



Article Tags :

Be the First to upvote.


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