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

If available, use scrot on Linux for ImageGrab #7100

Closed
wants to merge 5 commits into from

Conversation

HansBug
Copy link

@HansBug HansBug commented Apr 18, 2023

Use scrot when this environment have in ImageGrab.grab().

In practical use, although gnome-screenshot is widely present in Linux systems, in newer systems such as Ubuntu 20.04, there will be a full-screen animation effect when taking screenshots, and it is not easy to close. This feature may cause inconvenience to users in some tasks. Therefore, it has been changed to detect scrot. If scrot is present, it will be used directly. There will be no similar problems when taking screenshots with scrot, and it is very easy to install on Ubuntu and other systems with apt install -y scrot, and similar packages are available on other systems such as debian and centos.

Here are some more records about the annoying flash animation on gnome-screenshot @radarhere :

@radarhere radarhere changed the title dev(hansbug): use scrot when it have If available, use scrot on Linux for ImageGrab Apr 18, 2023
src/PIL/ImageGrab.py Outdated Show resolved Hide resolved
@radarhere
Copy link
Member

it is very easy to install on Ubuntu and other systems with apt install -y scrot

For the record, when testing I found I had to add the universe repository on Ubuntu before I could install it.

radarhere
radarhere previously approved these changes Apr 19, 2023
HansBug and others added 2 commits April 19, 2023 15:58
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@HansBug
Copy link
Author

HansBug commented Apr 19, 2023

For the record, when testing I found I had to add the universe repository on Ubuntu before I could install it.

I just tested the installation of scrot on Ubuntu 16.04/18.04/20.04 using a Docker image, and it worked fine. Next, I am going to test the installation on CentOS. It seems that scrot cannot be installed by yum install -y scrot. However, scrot is recommended in many similar application scenarios. For example, it is used to solve issues related to gnome-screenshot, and it is also used in the Linux platform screenshot function of pyautogui (it is worth noting that the Windows platform screenshot function in pyautogui is implemented based on the ImageGrab.grab method of Pillow). Therefore, scrot is widely used.

src/PIL/ImageGrab.py Outdated Show resolved Hide resolved
Co-authored-by: Ondrej Baranovič <3819630+nulano@users.noreply.github.com>
@radarhere radarhere dismissed their stale review April 26, 2023 10:09

Reconsidering usefulness

@radarhere
Copy link
Member

Back when we initially added gnome-screenshot, there was a link to a StackOverflow issue where scrot resulted "in a completely black image". Apparently, scrot doesn't work under Wayland. I tested, and yes, I found that it worked under X11, but not Wayland.

Ok, so scrot isn't useful for Wayland. But it's still useful for X11?

Well, Image.core.grabscreen_x11 already works under X11, and from what I can see, does not produce a white flash. So does supporting scrot actually provide any advantage?

Is the problem just a user trying to ignore gnome-screenshot when it is installed in favour of Image.core.grabscreen_x11? If so, then ImageGrab.grab(xdisplay=":0") should be sufficient with the current version of Pillow.

@radarhere
Copy link
Member

@HansBug any thoughts?

@HansBug
Copy link
Author

HansBug commented May 6, 2023

Is the problem just a user trying to ignore gnome-screenshot when it is installed in favour of Image.core.grabscreen_x11? If so, then ImageGrab.grab(xdisplay=":0") should be sufficient with the current version of Pillow.

Sorry for not responding earlier due to work-related reasons. I have just tested setting xdisplay=':0', and it ran on my end without any white flash. I believe this usage needs to be tested across different platforms. If the test is successful, it should be set as the default option. Otherwise, we still need to detect different environments and use different parameters and screenshot methods to avoid the occurrence of white flashes when using the default parameters.

@radarhere
Copy link
Member

Ok, I've created PR #7139 to prefer X11 over gnome-screenshot.

If no one is aware of a need for scrot, then it doesn't seem necessary to search through the many flavours of Linux trying to find a problem to match this solution.

@radarhere
Copy link
Member

PR #7143 has been merged.

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

Successfully merging this pull request may close these issues.

3 participants