Skip to content

Commit 2f67293

Browse files
authored
Merge pull request #1 from radarhere/image_grab_wayland_kde
Do not create temporary file if no utility is available
2 parents eeb494a + e685e28 commit 2f67293

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/PIL/ImageGrab.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ def grab(
7878
size, data = Image.core.grabscreen_x11(display_name)
7979
except OSError:
8080
if display_name is None and sys.platform not in ("darwin", "win32"):
81-
fh, filepath = tempfile.mkstemp(".png")
82-
os.close(fh)
8381
if shutil.which("gnome-screenshot"):
84-
subprocess.call(["gnome-screenshot", "-f", filepath])
82+
args = ["gnome-screenshot", "-f"]
8583
elif shutil.which("spectacle"):
86-
subprocess.call(["spectacle", "-n", "-b", "-f", "-o", filepath])
84+
args = ["spectacle", "-n", "-b", "-f", "-o"]
8785
else:
88-
os.unlink(filepath)
8986
raise
87+
fh, filepath = tempfile.mkstemp(".png")
88+
os.close(fh)
89+
subprocess.call(args + [filepath])
9090
im = Image.open(filepath)
9191
im.load()
9292
os.unlink(filepath)

0 commit comments

Comments
 (0)