Skip to content

lipoja/pyscreenshot

 
 

Repository files navigation

The pyscreenshot module can be used to copy the contents of the screen to a PIL or Pillow image memory using various back-ends. Replacement for the ImageGrab Module, which works on Windows only, so Windows users don't need this library. For handling image memory (e.g. saving to file, converting,..) please read PIL or Pillow documentation.

Links:

Travis Coveralls Latest Version Supported Python versions License Code Health Documentation

Goal:
Pyscreenshot tries to allow to take screenshots without installing 3rd party libraries. It is cross-platform but useful for Linux based distributions. It is only a pure Python wrapper, a thin layer over existing back-ends. Its strategy should work on most Linux distributions: a lot of back-ends are wrapped, if at least one exists then it works, if not then one back-end should be installed. Performance and interactivity are not important for this library.
Features:
Known problems:
Similar projects:

Examples

grab and show the whole screen:

#-- include('examples/showgrabfullscreen.py') --#
import pyscreenshot as ImageGrab

if __name__ == '__main__':

    # grab fullscreen
    im = ImageGrab.grab()

    # save image file
    im.save('screenshot.png')

    # show image in a window
    im.show()
#-#

to start the example:

python -m pyscreenshot.examples.showgrabfullscreen

grab and show the part of the screen:

#-- include('examples/showgrabbox.py')--#
import pyscreenshot as ImageGrab

if __name__ == '__main__':
    # part of the screen
    im = ImageGrab.grab(bbox=(10, 10, 510, 510))  # X1,Y1,X2,Y2
    im.show()
#-#

to start the example:

python -m pyscreenshot.examples.showgrabbox

Installation

General

  • install pip

  • install PIL or Pillow

  • install at least one back-end

  • install the program:

    # as root
    pip install pyscreenshot
    

Ubuntu 14.04

sudo apt-get install python-pip
sudo apt-get install python-pil
sudo pip install pyscreenshot
# optional back-ends
sudo apt-get install scrot imagemagick python-gtk2 python-qt4 python-wxgtk2.8 python-pyside
# optional for examples
sudo pip install entrypoint2

Uninstall

# as root
pip uninstall pyscreenshot

Command line interface

Back-end performance:

The performance can be checked with pyscreenshot.check.speedtest.

Example:

#-- sh('python -m pyscreenshot.check.speedtest --virtual-display 2>/dev/null') --#

n=10
------------------------------------------------------
wx                    1.2  sec        (  120 ms per call)
pygtk                 1.2  sec        (  124 ms per call)
pyqt                  1.4  sec        (  136 ms per call)
scrot                 0.93 sec        (   93 ms per call)
imagemagick           0.67 sec        (   67 ms per call)
pyside                1.3  sec        (  133 ms per call)
gnome-screenshot      18   sec        ( 1817 ms per call)
#-#

Print versions:

#-- sh('python -m pyscreenshot.check.versions 2> /dev/null ')--#
pyscreenshot         0.4.2
wx                   2.8.12.1
pygtk                2.28.6
pyqt                 4.10.4
scrot                0.8
imagemagick          6.7.7
pyside               1.2.1
gnome-screenshot     3.26.0
#-#

command line help

#-- sh('python -m pyscreenshot.check.speedtest --help')--#
usage: speedtest.py [-h] [-v] [--debug]

optional arguments:
  -h, --help            show this help message and exit
  -v, --virtual-display
  --debug               set logging level to DEBUG
#-#
#-- sh('python -m pyscreenshot.check.versions --help')--#
usage: versions.py [-h] [--debug]

optional arguments:
  -h, --help  show this help message and exit
  --debug     set logging level to DEBUG
#-#

Packages

No packages published

Languages

  • Python 100.0%