Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If available, use scrot on Linux for ImageGrab #7100

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions docs/reference/ImageGrab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ or the clipboard to a PIL image memory.
returned as an "RGBA" on macOS, or an "RGB" image otherwise.
If the bounding box is omitted, the entire screen is copied.

On Linux, if ``xdisplay`` is ``None`` then ``gnome-screenshot`` will be used if it
is installed. To capture the default X11 display instead, pass ``xdisplay=""``.
On Linux, if ``xdisplay`` is ``None`` then ``gnome-screenshot`` or ``scrot`` will
be used if they are installed. To capture the default X11 display instead, pass
``xdisplay=""``.
HansBug marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
7 changes: 5 additions & 2 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
left, top, right, bottom = bbox
im = im.crop((left - x0, top - y0, right - x0, bottom - y0))
return im
elif shutil.which("gnome-screenshot"):
elif shutil.which("gnome-screenshot") or shutil.which("scrot"):
radarhere marked this conversation as resolved.
Show resolved Hide resolved
fh, filepath = tempfile.mkstemp(".png")
os.close(fh)
subprocess.call(["gnome-screenshot", "-f", filepath])
if shutil.which("scrot"): # use scrot when have
HansBug marked this conversation as resolved.
Show resolved Hide resolved
subprocess.call([shutil.which("scrot"), "-z", "--overwrite", filepath])
radarhere marked this conversation as resolved.
Show resolved Hide resolved
else:
subprocess.call([shutil.which("gnome-screenshot"), "-f", filepath])
im = Image.open(filepath)
im.load()
os.unlink(filepath)
Expand Down