Skip to content

If available, use scrot on Linux for ImageGrab#7100

Closed
HansBug wants to merge 5 commits into
python-pillow:mainfrom
HansBug:dev/scrot
Closed

If available, use scrot on Linux for ImageGrab#7100
HansBug wants to merge 5 commits into
python-pillow:mainfrom
HansBug:dev/scrot

Conversation

@HansBug

@HansBug HansBug commented Apr 18, 2023

Copy link
Copy Markdown

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
Comment thread src/PIL/ImageGrab.py
Comment thread src/PIL/ImageGrab.py Outdated
@radarhere

Copy link
Copy Markdown
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.

Comment thread docs/reference/ImageGrab.rst Outdated
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

HansBug commented Apr 19, 2023

Copy link
Copy Markdown
Author

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.

Comment thread src/PIL/ImageGrab.py Outdated
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
Copy Markdown
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
Copy Markdown
Member

@HansBug any thoughts?

@HansBug

HansBug commented May 6, 2023

Copy link
Copy Markdown
Author

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
Copy Markdown
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
Copy Markdown
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