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

Support ImageGrab from clipboard on Linux via xclip and wl-clipboard #6751

Closed
AllanChain opened this issue Nov 21, 2022 · 6 comments · Fixed by #6783
Closed

Support ImageGrab from clipboard on Linux via xclip and wl-clipboard #6751

AllanChain opened this issue Nov 21, 2022 · 6 comments · Fixed by #6783
Labels

Comments

@AllanChain
Copy link

AllanChain commented Nov 21, 2022

Currently, grabclipboard raises NotImplementedError on Linux. But I think we can use xclip or wl-clipboard if they are installed. A subprocess call saving the image to a temporary file should be enough.

xclip -selection clipboard -t image/jpeg -o > test.jpg  # Edit 1
wl-paste --type image/jpg > test.jpg

I'm willing to help implement this feature.

What did you do?

Try to grab an image from the clipboard on Linux

What did you expect to happen?

The image is grabbed

What actually happened?

NotImplementedError: ImageGrab.grabclipboard() is macOS and Windows only

What are your OS, Python and Pillow versions?

  • OS: Linux (Manjaro KDE)
  • Python: 3.10.8
  • Pillow: 9.3.0
from PIL.ImageGrab import grabclipboard
grabclipboard()
@radarhere
Copy link
Member

Considering that we support gnome-screenshot in ImageGrab.grab, this seems reasonable.

@radarhere
Copy link
Member

radarhere commented Dec 7, 2022

I experimented with this, but found when I copied an image, xclip didn't work.

xclip.mov

I have however created PR #6783 for wl-paste.

@AllanChain
Copy link
Author

Sorry for the wrong command. I've tested the command for xclip in X11 environment and updated the command.

I don't know whether you are using X windows on Ubuntu when testing the xclip commands though.

@python-pillow python-pillow deleted a comment from AllanChain Dec 7, 2022
@radarhere
Copy link
Member

Thanks. I've added xclip to PR #6783 as well.

@benzen3
Copy link

benzen3 commented Oct 11, 2023

I'm trying to use ImageGrab in Google Colab and getting the error:

NotImplementedError: wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux
which brought me here.

wl-paste and xclip are not Python projects and so not supported in Google Colab.

Any workarounds possible?

@AllanChain
Copy link
Author

@benzen3 I think Python on Google Colab have no access to your system clipboard, because the Python process is running remotely. Therefore, it is impossible, and makes no sense, to support Google Colab.

As a workaround, you can try to run the notebook locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants