Python Forum
Want to take a Screenshot from a File in Linux - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Want to take a Screenshot from a File in Linux (/thread-21841.html)



Want to take a Screenshot from a File in Linux - dhiliptcs - Oct-17-2019

We are currently working manually to get a screen shot by opening every text files(screencapture from position A to position B) and save in png/jpeg format.

Is there any way to automate this in Python?

will pyscreenshot or PIL work in this case?
Just installed these LIBs.


RE: Want to take a Screenshot from a File in Linux - buran - Oct-17-2019

Never used pyscreenshot, but it looks it could do the job.
You can also check PyAutoGUI


RE: Want to take a Screenshot from a File in Linux - dhiliptcs - Oct-21-2019

I have got pyscreenshot (+ gtkpixbuf ) to do this activiy.

Code in gtkpixbuf.py as follows:
# http://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux


from PIL import Image
import tempfile

# based on:

class GtkPixbufWrapper(object):
    name = 'pygtk'
    childprocess = False

    def __init__(self):
        import gtk
        self.gtk = gtk
        try:
            gtk.gdk.Pixbuf
            gtk.gdk.COLORSPACE_RGB
        except AttributeError:
            raise ImportError(
                'Incompatible with Python3 / GDK3. Use gdk3pixbuf.')

    def grab(self, bbox=None):
        f = tempfile.NamedTemporaryFile(
            suffix='.png', prefix='pyscreenshot_gtkpixbuf_')
        filename = f.name
        self.grab_to_file(filename, bbox)
        im = Image.open(filename)
        return im

    def grab_to_file(self, filename, bbox=None):
        """http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html.

        only "jpeg" or "png"
        """


  
can anyone help how to invoke pyscreenshot and gtkpixbuf to get the screenshot of a given unix file