Cyril N.
Cyril N.

Reputation: 39859

Taking screenshot from a python script by selecting the area

I saw that post (that is really helpful : Take a screenshot via a python script. [Linux]) about taking a screenshot from python. It works well but I'd like to have the same behavior as gnome-screenshot : having the possibility to choose between :

Is there a way to do this in python, or, eventually, to use the gnome-screenshot application to do it, and then getting the file ?

I tried to find the perfect command line for gnome-screenshot to be launched without asking where to save the screenshot after by giving the path at the call, but I can't find it.

Thanks for your help!

Upvotes: 3

Views: 10374

Answers (2)

ponty
ponty

Reputation: 604

I have a wrapper project (pyscreenshot) for scrot, imagemagick, pyqt, wx and pygtk. If you have one of them, you can use it. Capturing an active window is missing.

Install:

easy_install pyscreenshot

Example:

import pyscreenshot as ImageGrab

# fullscreen
im=ImageGrab.grab()
im.show()

# part of the screen
im=ImageGrab.grab(bbox=(10,10,500,500))
im.show()

# to file
ImageGrab.grab_to_file('im.png')

Upvotes: 2

shang
shang

Reputation: 24802

If you are not limited to using using gnome-screenshot specifically, ImageMagick's import command can save directly to file without an interactive prompt.

See here for details: http://www.imagemagick.org/script/import.php

In addition to the command line interface, there is also a Python API.

Upvotes: 1

Related Questions