diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index 1ad4de63f72..cfde1c62745 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -69,7 +69,7 @@ def test_grabclipboard(self): ImageGrab.grabclipboard() assert ( str(e.value) - == "wl-paste is required for ImageGrab.grabclipboard() on Linux" + == "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux" ) return diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py index 12ad9ad71fe..8cf95680995 100644 --- a/src/PIL/ImageGrab.py +++ b/src/PIL/ImageGrab.py @@ -132,12 +132,16 @@ def grabclipboard(): return BmpImagePlugin.DibImageFile(data) return None else: - if not shutil.which("wl-paste"): + if shutil.which("wl-paste"): + args = ["wl-paste"] + elif shutil.which("xclip"): + args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"] + else: raise NotImplementedError( - "wl-paste is required for ImageGrab.grabclipboard() on Linux" + "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux" ) fh, filepath = tempfile.mkstemp() - subprocess.call(["wl-paste"], stdout=fh) + subprocess.call(args, stdout=fh) os.close(fh) im = Image.open(filepath) im.load()