Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 pyscreenshot Library Script to Capture Selected Area & Save it as PNG Image in Command Line

Posted on January 4, 2023

 

 

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

 

 

Python
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.

 

 

Python
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

 

 

 

Recent Posts

  • Node.js Tutorial to Export Images to PDF Document With Effects Using FilePix Library in Javascript
  • Node.js Tutorial to Export All Pages of PDF Document to Images and Save it in Javascript
  • Node.js OfficeGen Example to Add Text & Images in Powerpoint Presentation in Javascript
  • Node.js OfficeGen Example to Generate Excel Files By Adding Data inside Cells & Sheets in Javascript
  • Node.js OfficeGen Example to Create Word Docx Files & Add Text Images inside it Using Javascript
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme