#! /usr/bin/perl # ss makes a screenshot of the screen using import, and is released # under the terms of the GPL version 2, or any later version, at your # option. See the file README and COPYING for more information. # Copyright 2004 by Don Armstrong . # $Id$ use warnings; use strict; use Getopt::Long; use Pod::Usage; =head1 NAME ss - Take a screenshot of the screen, scale it, and upload it to a server =head1 SYNOPSIS ss [options] Options: --host, -H host to upload image to --dir, -D dir to place image (on host of -H set) --import-options, -I options to import (default -window root) --convert-options, -C options to convert (for scaling) --scale, -s make scaled image (default) --debug, -d debugging level (Default 0) --help, -h display this help --man, -m display manual =head1 OPTIONS =over =item B<--host, -H> The host where the image will be uploaded to using scp =item B<--dir, -D> The local (or remote if -H used) directory to place the resultant screenshots =item B<--import-options, -I> The options used to invoke import. By default, -window root. (Which will take a screenshot of the entire screen) =item B<--convert-options, -C> The options used to invoke convert, which will make a smaller image by default. Only usefull if -s is set (which it is by default.) =item B<--scale, -s> If set (the default) a smaller image is made. (Technically, convert is invoked with --convert-options, whether this scales depends on those options.) To forgo scaling, use -s0 or --scale=0. =item B<--debug, -d> Debug verbosity. (Default 0) =item B<--help, -h> Display brief useage information. =item B<--man, -m> Display this manual. =back =head1 EXAMPLES ss Will pretty much do what you want ss -I Will take a picture of a window you select. =cut use User; use File::Temp qw/tempfile tempdir/; use vars qw($DEBUG); # XXX parse config file my %options = (debug => 0, help => 0, man => 0, host => undef, dir => User->Home . '/ss', import_options => '-window root', import => 'import', convert => 'convert', convert_options => '-scale 25%', scale => 1, file_type => 'png', scp => 'scp', ); GetOptions(\%options,'host|H=s','import_options|I=s','file_type|t=s','scale|s!', 'convert_options|C=s','dir|D=s','debug|d+','help|h|?','man|m'); pod2usage() if $options{help}; pod2usage({verbose=>2}) if $options{man}; $DEBUG = $options{debug}; # XXX use perl's date command instead my ($sec,$min,$hour,$mday,$mon, $year,$wday,$yday,$isdst) = localtime(time); $year += 1900; my $date = qq($year).(${mon}+1).qq(${mday}_${hour}${min}${sec}); my $tempdir = undef; # use tempdir if host defined if (defined $options{host}) { $tempdir = $options{tempdir} || tempdir( CLEANUP => 1 ); print "chdir $tempdir\n" if $options{debug}; chdir $tempdir or die "Unable to chidr to $tempdir"; } else { print "chdir $options{dir}\n" if $options{debug}; chdir $options{dir} or die "Unable to chdir to $options{dir}"; } # import the image print qq($options{import} $options{import_options} ss_${date}.$options{file_type}\n) if $options{debug}; qx($options{import} $options{import_options} ss_${date}.$options{file_type}); # scale the image print qq($options{convert} $options{convert_options} ss_${date}.$options{file_type} ss_${date}_small.$options{file_type}\n) if $options{scale} and $options{debug}; qx($options{convert} $options{convert_options} ss_${date}.$options{file_type} ss_${date}_small.$options{file_type}) if $options{scale}; # upload if (defined $options{host}) { my $files = "ss_${date}.$options{file_type}"; $files .= " ss_${date}_small.$options{file_type}" if $options{scale}; print qq($options{scp} $files $options{host}:$options{dir}\n) if $options{debug}; qx($options{scp} $files $options{host}:$options{dir}); } __END__