From 1e092e95baf328cb7553eecb59e68481a31aa8f7 Mon Sep 17 00:00:00 2001 From: HansBug Date: Tue, 18 Apr 2023 12:50:47 +0800 Subject: [PATCH] dev(hansbug): use scrot when have --- src/PIL/ImageGrab.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py index 982f77f20..287529834 100644 --- a/src/PIL/ImageGrab.py +++ b/src/PIL/ImageGrab.py @@ -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"): fh, filepath = tempfile.mkstemp(".png") os.close(fh) - subprocess.call(["gnome-screenshot", "-f", filepath]) + if shutil.which("scrot"): # use scrot when have + subprocess.call([shutil.which("scrot"), "-z", "--overwrite", filepath]) + else: + subprocess.call([shutil.which("gnome-screenshot"), "-f", filepath]) im = Image.open(filepath) im.load() os.unlink(filepath)