- PIL Home
- Python Image Library Intro
- Python Image Library Setup
- Python Image Library Basics
- Python Image Library Hierarchy
- Python Image Library Modules
- Python ImageColor Module
- Python ImageDraw Module
- Python ImageStat Module
- Python ImageTK Module
- Python ImageFile Module
- Python ImageFilter Module
- Python ImageGrab Module
- Python ImageMath Module
- Python - Loading Image
- Python - Rotating Image
- Python - Blurring Image
- Python - Converting Image
- Python - Cropping Image
- Python - Image Thumbnails
- Python - Text on Images
- Python - Multiple Image Copies
- Python - Saving Image As PDF
- Python - Saving Screenshot
- Python - Resizing Image
- Python - Adding Watermark
- Python Image Library Resources
- Python - Quick Guide
- Python - Useful Resources
- Python - Discussion
Python ImageGrab Module
ImageGrab module
The ImageGrab module is used to capture the image of computer desktop or anything shown on the screen to a image format file.Everything that is on the desktop can be displayed.
ImageGrab module has two methods : grab and grabclipboard . grab method is used to capture the entire screen and grabclipboard method is used to grab only the clipboard image.
If the file cannot be opened, an IOError exception is raised.
Importing Image module
from PIL import ImageGrab
Image module functions
| ImageGrab.grab(bbox=None) | Take a snapshot of the screen. The pixels inside the bounding box are returned as an RGB image. If the bounding box is omitted, the entire screen is copied. |
| ImageGrab.grabclipboard() | Take a snapshot of the clipboard image, if any. |
Example
from PIL import ImageGrab
import time
#Screenshot is captured after 10 milliseconds
time.sleep(10)
im = ImageGrab.grab()
# file name will be created with the current time frame
screenshot = time.strftime("%Y%m%d-%H%M%S")
screenshot = screenshot + ".jpg"
print screenshot
im.save(screenshot)
im.show()
Advertisements