You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/usr/lib/python2.7/dist-packages/PIL/ImageGrab.py", line22, in<module>raiseImportError("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?
Reacted by 依云, JoseFernandoInsper, Oleh Skip, Prashant and jscul
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.
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).
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 :)
Reacted by Jeffrey 'Alex' Clark, Lesmana Zimmer, anatoly techtonik, Badam Akash Prasad, tahirhan, Pavak Paul, Bao, Bright Li and jscul
@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.
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.
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 :) )
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.
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 ?
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 )
Activity
techtonik commentedon Jul 15, 2016
Found this - http://stackoverflow.com/a/16141058/239247 - not sure if that is a good way.
Metallicow commentedon Jul 18, 2016
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.
lesmana commentedon Jul 18, 2016
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).
BoboTiG commentedon Oct 3, 2016
I am the developer of the MSS module. I changed the license for MIT in the
devbranch. 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 :)techtonik commentedon Oct 4, 2016
@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.
BoboTiG commentedon Oct 4, 2016
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.
BoboTiG commentedon Oct 6, 2016
Another update to notify that MSS has no more dependencies. Changes are in the
devbranch. Also, I created an example using PIL.rajatgoyal715 commentedon Oct 12, 2017
pyscreenshot library can be used
Refer here : https://stackoverflow.com/a/43636492/5463601
shish commentedon Oct 22, 2018
I'm interested in getting this working, but curious which approach to take since I don't own either of the libraries:
(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 :) )
BoboTiG commentedon Oct 22, 2018
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 :)
redstoneleo commentedon May 31, 2019
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 ?
shish commentedon May 31, 2019
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 )