mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-05 20:33:24 +03:00
Merge pull request #1 from radarhere/image_grab_wayland_kde
Do not create temporary file if no utility is available
This commit is contained in:
commit
2f672935eb
|
@ -78,15 +78,15 @@ def grab(
|
||||||
size, data = Image.core.grabscreen_x11(display_name)
|
size, data = Image.core.grabscreen_x11(display_name)
|
||||||
except OSError:
|
except OSError:
|
||||||
if display_name is None and sys.platform not in ("darwin", "win32"):
|
if display_name is None and sys.platform not in ("darwin", "win32"):
|
||||||
|
if shutil.which("gnome-screenshot"):
|
||||||
|
args = ["gnome-screenshot", "-f"]
|
||||||
|
elif shutil.which("spectacle"):
|
||||||
|
args = ["spectacle", "-n", "-b", "-f", "-o"]
|
||||||
|
else:
|
||||||
|
raise
|
||||||
fh, filepath = tempfile.mkstemp(".png")
|
fh, filepath = tempfile.mkstemp(".png")
|
||||||
os.close(fh)
|
os.close(fh)
|
||||||
if shutil.which("gnome-screenshot"):
|
subprocess.call(args + [filepath])
|
||||||
subprocess.call(["gnome-screenshot", "-f", filepath])
|
|
||||||
elif shutil.which("spectacle"):
|
|
||||||
subprocess.call(["spectacle", "-n", "-b", "-f", "-o", filepath])
|
|
||||||
else:
|
|
||||||
os.unlink(filepath)
|
|
||||||
raise
|
|
||||||
im = Image.open(filepath)
|
im = Image.open(filepath)
|
||||||
im.load()
|
im.load()
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user