-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
pshot
executable file
·99 lines (74 loc) · 2.14 KB
/
pshot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl
# vim: ft=perl:
# abstract: take screenshot, transfer it to host and return url
our $APP = 'pshot';
our $VERSION = '0.21';
use strict;
use Getopt::Long;
use Pod::Usage;
my $base = 'http://i.japh.se';
my $ssh_host = '192.168.1.128';
my $ssh_user = 'scp1';
my $ssh_port = 19216;
our($opt_bbcode,$opt_html);
GetOptions(
bbcode => \$opt_bbcode,
html => \$opt_html,
'-h' => sub { pod2usage(verbose => 1) && exit(0); },
man => sub { pod2usage(verbose => 3) && exit(0); },
);
my $dname = '';
if(@ARGV) {
$dname .= "/" . shift(@ARGV);
}
print shot(),"\n";
sub shot {
my $fname = 'pshot-' . time();
system("scrot -q 100 $fname.png -t 7%") == 0 or die("scrot failed: $!");
system(
'ssh', '-p', $ssh_port,
"$ssh_user\@$ssh_host", "mkdir -p http/japh.se/scrots/_full/$dname"
) == 0 or(die("ssh failed: $!"));
# dupe STDOUT so we can reopen it when we wanna be loud
open(OLD_STDOUT, '>&', STDOUT) or die("stddd$!");
close(STDOUT);
system(
'scp', '-P', $ssh_port,
"$fname.png",
"$fname-thumb.png",
"$ssh_user\@$ssh_host:http/japh.se/scrots/_full/$dname",
) == 0 or(die("scp failed: $!"));
unlink("$fname.png") or print "$fname.png: $!" and exit(-1);
unlink("$fname-thumb.png") or print "$fname-thumb.png: $!" and exit(-1);
open(STDOUT, '>&', OLD_STDOUT) or die($!);
if($opt_html) {
return("<a href=\"$base/$fname.png\">");
}
elsif($opt_bbcode) {
return(
"[url=$base/$fname.png][img]$base/$fname-thumb.png\[/img][/url]"
);
}
else {
return("$base/$fname.png");
}
exit(0);
}
=pod
=head1 NAME
pshot - screenshot automation tool
=head1 DESCRIPTION
phshot takes a screenshot, transfers it to a remote host and return the
resulting URI (assuming remote httpd). HTML style notation and BBCode syntax
is optional.
=head1 OPTIONS
-b, --bbcode return the uri in bbcode syntax
-ht, --html return the uri wrapped in html href syntax
-h, --help show the help and exit
-m, --man show the manual and exit
=head1 AUTHOR
Written by Magnus Woldrich.
License: PerlArtistic
=head1 COPYRIGHT
Copyright (C) Magnus Woldrich 2010
=cut