asweigart / pyscreeze

PyScreeze is a simple, cross-platform screenshot module for Python 2 and 3.
BSD 3-Clause "New" or "Revised" License
188 stars 95 forks source link

-a option for scrot #68

Open liusida opened 3 years ago

liusida commented 3 years ago

Thanks for providing such an interesting tool!

If on Linux, when passing region into the screenshot(), it will be faster to utilize the -a option for scrot.

Basically, we can change this line https://github.com/asweigart/pyscreeze/blob/master/pyscreeze/__init__.py#L475 to something like:

        if region is None:
            subprocess.call(['scrot', '-z', tmpFilename])
        else:
            str_region = ','.join([str(x) for x in region])
            subprocess.call(['scrot', '-a', str_region, '-z', tmpFilename])

I tested the difference between two versions use this code snippet:

for i in range(100):
    screenshot = pyscreeze.screenshot(region=(0, 0, 300, 600))

The -a version only took 3s while the default version took 33s. (I have two monitors :)

Thanks again!

theColourSpace commented 3 years ago

Related, I'm finding using maim even faster than scrot.

https://github.com/naelstrof/maim

theColourSpace commented 3 years ago

@liusida I created a branch that uses 'maim' which allows regions and stdout. Drastically speeding up the process. If you're interested.

https://github.com/theColourSpace/pyscreeze/tree/linux-maim