summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2010-12-26 10:02:13 +0100
committerDaniel Friesel <derf@finalrewind.org>2010-12-26 10:02:13 +0100
commit631d723fed7dfdcab1e7bd731a143c2bed453e6d (patch)
treed2f584c7638d7163cc17ade3c899e7c488e0b55f
parenta004cce37bd18272b236fafc250367325dd15556 (diff)
Add vcalendar
-rwxr-xr-xbin/vcalendar47
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/vcalendar b/bin/vcalendar
new file mode 100755
index 0000000..502d900
--- /dev/null
+++ b/bin/vcalendar
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.010;
+use autodie;
+
+use GD;
+use Getopt::Std;
+
+my %opts;
+
+getopts('a:cfgC:', \%opts);
+
+my $alpha = $opts{'a'} // 0;
+
+my $im = GD::Image->new(200, 40);
+$im->saveAlpha(1);
+
+my $fg = $im->colorAllocateAlpha( 0, 0, 0, $alpha);
+my $bg = $im->colorAllocateAlpha( 0, 0, 0, 127);
+
+if ($opts{'C'}) {
+ $fg = $im->colorAllocateAlpha(split(qr{,}, $opts{'C'}), $alpha);
+}
+
+my @lines = split(/\n/, qx{calendar});
+
+if ($opts{'c'}) {
+ say join("\n", @lines);
+}
+elsif ($opts{'g'}) {
+ $im->filledRectangle(0, 0, 200, 40, $bg);
+
+ for my $i (0 .. $#lines) {
+ $lines[$i] =~ s{\t}{};
+ $im->string(gdSmallFont, 2, 2 + (10 * $i), $lines[$i], $fg);
+ }
+
+ open(my $out_fh, '>', '/tmp/vcalendar.png');
+ binmode $out_fh;
+ print $out_fh $im->png();
+ close($out_fh);
+}
+
+if ($opts{'f'}) {
+ exec('feh', '/tmp/vcalendar.png');
+}