Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Tests/test_imagegrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def test_grab_x11(self) -> None:

@pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB")
def test_grab_no_xcb(self) -> None:
if sys.platform not in ("win32", "darwin") and not shutil.which(
"gnome-screenshot"
if (
sys.platform not in ("win32", "darwin")
and not shutil.which("gnome-screenshot")
and not shutil.which("spectacle")
):
with pytest.raises(OSError) as e:
ImageGrab.grab()
Expand Down
5 changes: 3 additions & 2 deletions docs/reference/ImageGrab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ or the clipboard to a PIL image memory.
the entire screen is copied, and on macOS, it will be at 2x if on a Retina screen.

On Linux, if ``xdisplay`` is ``None`` and the default X11 display does not return
a snapshot of the screen, ``gnome-screenshot`` will be used as fallback if it is
installed. To disable this behaviour, pass ``xdisplay=""`` instead.
a snapshot of the screen, ``gnome-screenshot`` or ``spectacle`` will be used as a
fallback if they are installed. To disable this behaviour, pass ``xdisplay=""``
instead.

.. versionadded:: 1.1.3 (Windows), 3.0.0 (macOS), 7.1.0 (Linux)

Expand Down
14 changes: 8 additions & 6 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@
raise OSError(msg)
size, data = Image.core.grabscreen_x11(display_name)
except OSError:
if (
display_name is None
and sys.platform not in ("darwin", "win32")
and shutil.which("gnome-screenshot")
):
if display_name is None and sys.platform not in ("darwin", "win32"):
if shutil.which("gnome-screenshot"):
args = ["gnome-screenshot", "-f"]

Check warning on line 82 in src/PIL/ImageGrab.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageGrab.py#L82

Added line #L82 was not covered by tests
elif shutil.which("spectacle"):
args = ["spectacle", "-n", "-b", "-f", "-o"]

Check warning on line 84 in src/PIL/ImageGrab.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageGrab.py#L84

Added line #L84 was not covered by tests
else:
raise
fh, filepath = tempfile.mkstemp(".png")
os.close(fh)
subprocess.call(["gnome-screenshot", "-f", filepath])
subprocess.call(args + [filepath])

Check warning on line 89 in src/PIL/ImageGrab.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageGrab.py#L89

Added line #L89 was not covered by tests
im = Image.open(filepath)
im.load()
os.unlink(filepath)
Expand Down
Loading