public
Description: Automatic approximation of typical Photoshop actions
Homepage: http://rcrowley.org/2007/11/08/introducing-curvr/
Clone URL: git://github.com/rcrowley/curvr.git
curvr / curvrmail
100755 141 lines (118 sloc) 2.906 kb
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
 
#
# curvr
# Richard Crowley <r@rcrowley.org>
#
 
# This works with my Nokia N82. I don't care if it works on your phone.
# Tread lightly.
 
use strict;
 
# Flickr API goodness
my $FLICKR_API_KEY = '';
my $FLICKR_SECRET = '';
my $FLICKR_TOKEN = '';
 
# Fire Bagel!
my $FIREEAGLE_CONSUMER_KEY = '';
my $FIREEAGLE_CONSUMER_SECRET = '';
my $FIREEAGLE_ACCESS_TOKEN = '';
my $FIREEAGLE_ACCESS_SECRET = '';
 
my $CURVR_BIN = 'curvr';
my $CURVR_PROCESS = 'curve';
my $CURVR_VERSION = '0.2.1';
 
 
 
use MIME::Base64;
use Flickr::Upload::FireEagle;
 
# Tags to add to every photo
my $TAGS = "curvr curvr:process=$CURVR_PROCESS curvr:version=$CURVR_VERSION";
 
# Get the raw email body from procmail
my @lines = <STDIN>;
my $boundary = '';
my $content_type = '';
my $blank = 0;
my @body;
my @jpeg;
foreach (@lines) {
chomp;
 
# First we have to find the boundary
if (!$boundary && '--' eq substr($_, 0, 2)) {
$boundary = $_;
}
 
# Seeing another boundary indicates the end of a part
elsif ($boundary eq $_) {
$content_type = '';
$blank = 0;
}
 
# Note the content type if this line specifies it
elsif (/^Content-Type: ([a-z\/]+)/) {
$content_type = $1;
}
 
# Now find the blank line that indicates the beginning of content
elsif (!$blank && /^\s*$/) {
$blank = 1;
}
 
# The body
elsif ($blank && 'text/plain' eq $content_type) {
push @body, $_;
}
 
# The JPEG attachment
elsif ($blank && 'image/jpeg' eq $content_type) {
push @jpeg, $_;
}
 
}
my $body = join '', @body;
 
# Curvr ur JPEG
my $ts = time();
my $in = "/tmp/curvrmail_$ts.jpg";
my $out = "/tmp/curvrmail_${ts}_curve.jpg";
unlink $in;
open JPEG, '>', $in;
print JPEG decode_base64(join('', @jpeg));
close JPEG;
`$CURVR_BIN $in $CURVR_PROCESS $out`;
 
# Sneaky rotate syntax
# Why doesn't my phone have an accelerometer in it?
my $tags = '';
if ($body =~ /^([lr])\s+/i) {
my $rotate = lc($1);
my $degrees = '0';
if ('l' eq $rotate) {
$degrees = '-90';
$tags = 'curvr:rotate=left';
} elsif ('r' eq $rotate) {
$degrees = '90';
$tags = 'curvr:rotate=right';
}
`gm convert $out -rotate $degrees $out`;
$body =~ s/^[lr]\s+//i;
}
 
# Pick apart title and tags
my $title = '';
if ($body =~ /^(.*)tags:(.*)$/i) {
$title = $1;
$tags = "$2 $tags";
} else {
$title = $body;
}
$title =~ s/^\s+//;
$title =~ s/\s+$//;
$tags =~ s/^\s+//;
$tags =~ s/\s+$//;
$tags .= " $TAGS";
 
# Upload with Fire Bagel
my %fireeagle = (
'consumer_key' => $FIREEAGLE_CONSUMER_KEY,
'consumer_secret' => $FIREEAGLE_CONSUMER_SECRET,
'access_token' => $FIREEAGLE_ACCESS_TOKEN,
'access_token_secret' => $FIREEAGLE_ACCESS_SECRET,
'tagify' => 'delicious'
);
my %flickr = (
'key' => $FLICKR_API_KEY,
'secret' => $FLICKR_SECRET,
'fireeagle' => \%fireeagle
);
my $uploadr = Flickr::Upload::FireEagle->new(\%flickr);
my $photo_id = $uploadr->upload(
'photo' => $out,
'auth_token' => $FLICKR_TOKEN,
'title' => $title,
'tags' => $tags
);