#!/usr/bin/env python # -*- coding: utf-8 -*- ########################################################################### # Screenshot. # # Copyright (C) 2010 Fotis Tsamis # Many thanks to Uli Schlachter for helping with the cairo stuff # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FINESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # On Debian GNU/Linux systems, the complete text of the GNU General # Public License can be found in `/usr/share/common-licenses/GPL". ############################################################################ import gtk.gdk as gdk from sys import stdout, stderr, argv if len(argv) == 3: width, height = int(argv[1]), int(argv[2]) else: exit(1) root = gdk.get_default_root_window() if root is None: exit(1) r_width, r_height = root.get_size() pmap = gdk.Pixmap(root, width, height) cr = pmap.cairo_create() cr.scale(float(width)/r_width, float(height)/r_height) cr.set_source_pixmap(root, 0, 0) cr.paint() pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, width, height) pixbuf.get_from_drawable(pmap, root.get_colormap(), 0, 0, 0, 0, width, height) rowst = str(pixbuf.get_rowstride()) pixels = pixbuf.get_pixels() try: stdout.flush() stdout.write('%s\n%ix%i\n%s' %(rowst, width, height, pixels)) stdout.flush() except: stderr.write("Error while sending screenshot\n")