Skip to content

ImageGrab on Linux #2028

Closed
Closed

Description

@techtonik

What did you do?

Got Ubuntu 16.04.

>>> from PIL import ImageGrab

What did you expect to happen?

>>>

What actually happened?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/PIL/ImageGrab.py", line 22, in <module>
    raise ImportError("ImageGrab is OS X and Windows only")

What versions of Pillow and Python are you using?

>>> PIL.VERSION
'1.1.7'
>>> PIL.PILLOW_VERSION
'3.1.2'

So, what is the proper way for saving screens on Linux?

Activity

  1. techtonik commented on Jul 15, 2016

    @techtonik
    ContributorAuthor

    Found this - http://stackoverflow.com/a/16141058/239247 - not sure if that is a good way.

  2. Metallicow commented on Jul 18, 2016

    @Metallicow
    Contributor

    Second thought:
    pyscreenshot https://pypi.python.org/pypi/pyscreenshot is a replacement module for ImageGrab.
    But yes, it would be nice to have ImageGrab completely cross compatible in the Pillow library.
    Maybe try asking the author to license it under PIL/Pillow license.
    Or look at the code and review what changes might need to ImageGrab and implement them similarly in the module.

  3. lesmana commented on Jul 18, 2016

    @lesmana

    https://github.com/BoboTiG/python-mss

    it seems to do all the work itself without calling other tools. it claims to work on all platforms. cannot test because i do not have windows nor mac.

    license is zlib/libpng. do not know how easy it is to integrate code in PIL/Pillow MIT like license.

    pyscreenshot seems to be "just" a python wrapper around other tools. a quick glance in the source code revealed many subprocess calls (via EasyProcess). ironically PIL/Pillow itself is one of the wrapped tools (only on windows).

  4. BoboTiG commented on Oct 3, 2016

    @BoboTiG

    I am the developer of the MSS module. I changed the license for MIT in the dev branch. I added a good documentation and tests are coming. If you are interested in the use of my work and need few adjustments in the API, we can talk :)

  5. added this to the Future milestone on Oct 3, 2016
  6. techtonik commented on Oct 4, 2016

    @techtonik
    ContributorAuthor

    @BoboTiG basically Pillow needs to know what is the format of raw data that is returned from some screenshot call to give it a type. Another issue is that PIL code doesn't have any install dependencies, so either include the code as-is, or make it as optional dependency. @aclark4life should know better what is the proper way to resolve this with PR.

  7. BoboTiG commented on Oct 4, 2016

    @BoboTiG

    The format is always simple "RGB". For the unique dependence, it is optional but will boost the screenshot. I am still working on to speed-up the process.

  8. BoboTiG commented on Oct 6, 2016

    @BoboTiG

    Another update to notify that MSS has no more dependencies. Changes are in the dev branch. Also, I created an example using PIL.

  9. rajatgoyal715 commented on Oct 12, 2017

    @rajatgoyal715
  10. shish commented on Oct 22, 2018

    @shish

    I'm interested in getting this working, but curious which approach to take since I don't own either of the libraries:

    • copy-paste code from mss into pillow (all the users get fast, cross-platform screenshots all the time, but code is duplicated between pillow and mss - I'm not sure if @BoboTiG is happy to have his code "stolen" like this, or if the Pillow maintainers are happy to maintain the code; but as an end user I like this approach because everything is awesome out of the box)
    • add mss as an optional dependency from pillow, and have ImageGrab just become a simple wrapper, replacing the current code, raising an exception if mss isn't installed (users get fast cross-platform screenshots, but they need to install an extra library)
    • add mss as an optional dependency, and keep the current ImageGrab code as a fallback (the most compatibility; but ImageGrab will be slow by default, and there's more code to maintain, and there's no way for users to know that they could get a 100x performance improvement by installing mss)
    • add mss as a hard dependency (This would also be good as an end user, but if I'm understanding correctly, Pillow has a rule of "no hard dependencies"?)

    (For context to why I want to do this - I've been looking for a fast cross-platform imagegrab library for years, but everywhere I looked the advice was "use Pillow or PyScreenshot"; both of those are slow, so I ended up writing my own python extension in C. MSS is amazing, but despite searching for it for years, I never found it. I think the world would be a better place if we combined the well-known-and-widely-used-ness of Pillow with the awesome implementation from MSS :) )

  11. BoboTiG commented on Oct 22, 2018

    @BoboTiG

    Thanks @shish !

    IMO the option 1 is not ideal for either part. Code duplication will result in too many issues, patches not sent upstream or big code difference between implementations with time.

    Option 2 may be good. It can let the user to not use MSS. A simple warning can be triggered if not installed (noisy but skipable by users).

    I think the option 3 will be useless. Users will continue to have a slowly (and in many cases not working at all) version without notice. Most people will not be aware at all of the alternative way.

    Option 4 is a good, but it is not my voice here :)

    I can think of a 5th option: vendoring. PyPi is doing that and it seems to work pretty well. Issues and patches should be opened upstream and changes will automatically by available with the next Pillow release. The only drawback is that you can't have an up-to-date MSS version depending of the release process of Pillow. Using the option 4 will allow user to simple have the latest MSS version more quickly.

    BTW thanks for compliments :)

  12. redstoneleo commented on May 31, 2019

    @redstoneleo

    As I 've tested , PyScreenshot is not slow on Linux , instead I felt it is really fast, so any consideration on incorporating the Linux part of PyScreenshot into this project ?

  13. shish commented on May 31, 2019

    @shish

    What is "fast" for you? PyScreenshot's own benchmarks in the README say that the fastest backend is ~340ms to take a screenshot, compared to ~5ms using native functions like mss does...

    (But still, having imagegrab work on Linux would be nice for a lot of people, even if it doesn't work for real-time needs :P )

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    LinuxPlatformA catchall for platform-related

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions