Welcome folks today in this blog post we will be capturing selected area
and save it as png image
in command line using python
. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the below libraries using the pip
command as shown below
pip install pyscreenshot
And after that you need to make an app.py
file and copy paste the following code
app.py
1 2 |
import pyscreenshot pic = pyscreenshot.grab(bbox=(81, 135, 500, 300)) |
As you can see we are importing the pyscreenshot
library at the very top and then we are using the grab()
method to draw box
or select portion of the screen using the x
and y
coordinates. And also we are passing the width
and the height
of the window as well in this method.
1 2 |
pic.show() pic.save("ss.png") |
And then we are using the show()
method to show the image
on the screen in the window. And then we are saving
the image using the save()
method and then we are passing the filename
of the image.
Now if you run the app.py
file using the command line
python app.py