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:
- home: https://github.com/ponty/pyscreenshot
- documentation: http://pyscreenshot.readthedocs.org
- PYPI: https://pypi.python.org/pypi/pyscreenshot
- 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:
- Cross-platform wrapper
- Capturing the whole desktop
- Capturing an area
- saving to PIL or Pillow image memory
- some back-ends are based on this discussion: http://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux
- pure Python library
- supported python versions: 2.6, 2.7, 3.2, 3.3, 3.4
- 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:
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
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
# as root
pip uninstall pyscreenshot
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==>
# <== 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==>