Skip to content

Cloudxtreme/pyscreenshot

 
 

Repository files navigation

The pyscreenshot module can be used to copy the contents of the screen to a PIL or Pillow image memory. Replacement for the ImageGrab Module, which works on Windows only. 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 Downloads 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:
  • different back-ends generate slightly different images from the same desktop, this should be investigated
  • ImageMagick creates blackbox on some systems
  • PyGTK back-end does not check $DISPLAY -> not working with Xvfb
  • slow: 0.2s - 0.7s
Similar projects:

Examples

grab and show the whole screen :

# <== include('examples/showgrabfullscreen.py')==>
from entrypoint2 import entrypoint
from pyscreenshot import grab


@entrypoint
def show(backend='auto'):
    if backend == 'auto':
        backend = None
    im = grab(bbox=(100, 200, 300, 400), backend=backend)
    im.show()
# <==end==>

to start the example:

python -m pyscreenshot.examples.showgrabfullscreen

grab and show the part of the screen :

# <== include('examples/showgrabbox.py')==>
from entrypoint2 import entrypoint
from pyscreenshot import grab


@entrypoint
def show(backend='auto'):
    if backend == 'auto':
        backend = None
    im = grab(bbox=(100, 200, 300, 400), backend=backend)
    im.show()
# <==end==>

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

sudo apt-get install python-pip
sudo pip install pyscreenshot
sudo apt-get install python-imaging
# optional back-ends
sudo apt-get install scrot
sudo apt-get install imagemagick
sudo apt-get install python-gtk2
sudo apt-get install python-qt4
# optional for examples
sudo pip install entrypoint2

Uninstall

# as root
pip uninstall pyscreenshot

Command line interface

Back-end performance:

# <== sh('python -m pyscreenshot.check.speedtest')==>

n=10   to_file: True   bounding box: None
------------------------------------------------------
Forced backend not found, or cannot be loaded:pil
scrot                 1.5  sec    (  145 ms per call)
wx                    1.4  sec    (  138 ms per call)
pygtk                 1.7  sec    (  165 ms per call)
pyqt                  1.1  sec    (  112 ms per call)
imagemagick           6.1  sec    (  610 ms per call)
Forced backend not found, or cannot be loaded:mac_screencapture
Forced backend not found, or cannot be loaded:mac_quartz

n=10   to_file: False  bounding box: None
------------------------------------------------------
Forced backend not found, or cannot be loaded:pil
scrot                 1.5  sec    (  152 ms per call)
wx                    0.19 sec    (   18 ms per call)
pygtk                 1.7  sec    (  166 ms per call)
pyqt                  1    sec    (  101 ms per call)
imagemagick           6    sec    (  604 ms per call)
Forced backend not found, or cannot be loaded:mac_screencapture
Forced backend not found, or cannot be loaded:mac_quartz

n=10   to_file: False  bounding box: (10, 10, 20, 20)
------------------------------------------------------
Forced backend not found, or cannot be loaded:pil
scrot                 1.9  sec    (  186 ms per call)
wx                    0.19 sec    (   18 ms per call)
pygtk                 0.0047 sec  (    0 ms per call)
pyqt                  1.4  sec    (  135 ms per call)
imagemagick           4.5  sec    (  449 ms per call)
Forced backend not found, or cannot be loaded:mac_screencapture
Forced backend not found, or cannot be loaded:mac_quartz
# <==end==>

Print versions:

# <== sh('python -m pyscreenshot.check.versions')==>
pyscreenshot         0.3.4
pil                  missing
scrot                0.8
wx                   2.8.12.1
pygtk                2.28.6
pyqt                 not implemented
imagemagick          6.7.7
mac_screencapture    missing
mac_quartz           missing
# <==end==>

command line help

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

optional arguments:
  -h, --help  show this help message and exit
  --debug     set logging level to DEBUG
# <==end==>
# <== 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
# <==end==>

Packages

No packages published

Languages

  • Python 100.0%