Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5b64d4b

Browse filesBrowse files
committed
Update screenshot.py and Tutorial to use Pillow image library (cztomczak#357)
1 parent 7145ffa commit 5b64d4b
Copy full SHA for 5b64d4b

File tree

Expand file treeCollapse file tree

3 files changed

+25
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-18
lines changed
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ __pycache__/
55
*.pyc
66
cefclient
77
webcache/
8+
examples/screenshot.png
Collapse file

‎docs/Tutorial.md‎

Copy file name to clipboardExpand all lines: docs/Tutorial.md
+5-4Lines changed: 5 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,11 @@ size set to 800px width and 5000px height which is an equivalent
491491
of scrolling down page multiple times, but you get all this in
492492
one single screenshot.
493493

494-
Before running this script you must install PIL image library:
494+
Before running this script you have to install Pillow image
495+
library (PIL module):
495496

496497
```text
497-
pip install PIL
498+
pip install Pillow
498499
```
499500

500501
This example accepts optional arguments so that you can change
@@ -503,7 +504,7 @@ url and viewport size. Example usage:
503504
```text
504505
python screenshot.py
505506
python screenshot.py https://github.com/cztomczak/cefpython 1024 5000
506-
python screenshot.py https://www.google.com/ 800 600
507+
python screenshot.py https://www.google.com/ncr 1024 768
507508
```
508509

509510
Let's discuss code in this example.
@@ -591,7 +592,7 @@ OnLoadingStateChange callbacks notifies when web page loading
591592
completes and OnLoadError callback notifies if loading of
592593
page failed. When loading succeeds a function save_screenshot()
593594
is called which retrieves image buffer that was earlier stored
594-
in the browser object and then uses PIL image library to save
595+
in the browser object and then uses Pillow image library to save
595596
it as a PNG image.
596597

597598
At the end, it is worth noting that there is yet an another
Collapse file

‎examples/screenshot.py‎

Copy file name to clipboardExpand all lines: examples/screenshot.py
+19-14Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55
This example is discussed in Tutorial in the Off-screen
66
rendering 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
1819
Usage:
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

2629
from cefpython3 import cefpython as cef
@@ -30,10 +33,10 @@
3033
import sys
3134

3235
try:
33-
from PIL import Image
36+
from PIL import Image, PILLOW_VERSION
3437
except:
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

6367
def 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.