Python Forum

Full Version: Want to take a Screenshot from a File in Linux
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Never used pyscreenshot, but it looks it could do the job.
You can also check PyAutoGUI
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