55This example is discussed in Tutorial in the Off-screen
66rendering section.
77
8- You have to install PIL image library before running script:
8+ Before running this script you have to install Pillow image
9+ library (PIL module):
910
10- pip install PIL
11+ pip install Pillow
1112
12- With optionl arguments to this script you can resize viewport so
13- that screenshot includes whole page with height like 5000 px which
14- would be an equivalent of scrolling down multiple pages. By default
15- when no arguments are provided will load cefpython project page
16- on Github with 5000 px height.
13+ With optionl arguments to this script you can resize viewport
14+ so that screenshot includes whole page with height like 5000px
15+ which would be an equivalent of scrolling down multiple pages.
16+ By default when no arguments are provided will load cefpython
17+ project page on Github with 5000 px height.
1718
1819Usage:
1920 python screenshot.py
2021 python screenshot.py https://github.com/cztomczak/cefpython 1024 5000
21- python screenshot.py https://www.google.com/ 800 600
22+ python screenshot.py https://www.google.com/ncr 1024 768
2223
23- Tested with CEF Python v57.0+
24+ Tested configurations:
25+ - CEF Python v57.0+
26+ - Pillow 2.3.0 / 4.1.0
2427"""
2528
2629from cefpython3 import cefpython as cef
3033import sys
3134
3235try :
33- from PIL import Image
36+ from PIL import Image , PILLOW_VERSION
3437except :
3538 print ("[screenshot.py] Error: PIL module not available. To install"
36- " type: pip install PIL " )
39+ " type: pip install Pillow " )
3740 sys .exit (1 )
3841
3942
@@ -48,6 +51,7 @@ def main():
4851 check_versions ()
4952 sys .excepthook = cef .ExceptHook # To shutdown all CEF processes on error
5053 if os .path .exists (SCREENSHOT_PATH ):
54+ print ("[screenshot.py] Remove old screenshot" )
5155 os .remove (SCREENSHOT_PATH )
5256 command_line_arguments ()
5357 # Off-screen-rendering requires setting "windowless_rendering_enabled"
@@ -56,14 +60,15 @@ def main():
5660 create_browser ()
5761 cef .MessageLoop ()
5862 cef .Shutdown ()
59- print ("[screenshot.py] Opening screenshot using default application" )
60- open_in_default_application (SCREENSHOT_PATH )
63+ print ("[screenshot.py] Opening screenshot with default application" )
64+ open_with_default_application (SCREENSHOT_PATH )
6165
6266
6367def check_versions ():
6468 print ("[screenshot.py] CEF Python {ver}" .format (ver = cef .__version__ ))
6569 print ("[screenshot.py] Python {ver} {arch}" .format (
6670 ver = platform .python_version (), arch = platform .architecture ()[0 ]))
71+ print ("[screenshot.py] Pillow {ver}" .format (ver = PILLOW_VERSION ))
6772 assert cef .__version__ >= "57.0" , "CEF Python v57.0+ required to run this"
6873
6974
@@ -124,7 +129,7 @@ def save_screenshot(browser):
124129 print ("[screenshot.py] Saved image: {path}" .format (path = SCREENSHOT_PATH ))
125130
126131
127- def open_in_default_application (path ):
132+ def open_with_default_application (path ):
128133 if sys .platform .startswith ("darwin" ):
129134 subprocess .call (("open" , path ))
130135 elif os .name == "nt" :
0 commit comments