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
- time: 0.1s - 1.0s
- Known problems:
- ImageMagick creates blackbox on some systems
- PyGTK back-end does not check $DISPLAY -> not working with Xvfb
- Similar projects:
grab and show the whole screen:
#-- include('examples/showgrabfullscreen.py') --# import pyscreenshot as ImageGrab if __name__ == "__main__": # fullscreen im=ImageGrab.grab() 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
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 ------------------------------------------------------ wx 2.4 sec ( 235 ms per call) pygtk 2 sec ( 200 ms per call) pyqt 4.6 sec ( 455 ms per call) scrot 1.6 sec ( 163 ms per call) imagemagick 6.4 sec ( 644 ms per call) n=10 to_file: False bounding box: None ------------------------------------------------------ wx 1 sec ( 104 ms per call) pygtk 2.6 sec ( 257 ms per call) pyqt 2.5 sec ( 251 ms per call) scrot 2.4 sec ( 236 ms per call) imagemagick 6.5 sec ( 647 ms per call) n=10 to_file: False bounding box: (10, 10, 20, 20) ------------------------------------------------------ wx 0.9 sec ( 90 ms per call) pygtk 0.39 sec ( 39 ms per call) pyqt 2.4 sec ( 241 ms per call) scrot 2 sec ( 197 ms per call) imagemagick 4.5 sec ( 445 ms per call) #-#
Print versions:
#-- sh('python -m pyscreenshot.check.versions')--# pyscreenshot 0.3.4 wx 2.8.12.1 pygtk 2.28.6 pyqt not implemented scrot 0.8 imagemagick 6.7.7 #-#
#-- 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 #-#
#-- 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 #-#