From c20f8bdc969773d209516ac7235fbae0605728a7 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 13 Jul 2011 22:40:00 +0200 Subject: Create multi-purpose vwrap script --- bin/vcalendar | 61 ---------------------------------------------------- bin/vwrap | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 61 deletions(-) delete mode 100755 bin/vcalendar create mode 100755 bin/vwrap diff --git a/bin/vcalendar b/bin/vcalendar deleted file mode 100755 index 73995f7..0000000 --- a/bin/vcalendar +++ /dev/null @@ -1,61 +0,0 @@ -#!/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, 80); -$im->saveAlpha(1); - -my $white = $im->colorAllocateAlpha(255, 255, 255, $alpha); -my $gray = $im->colorAllocateAlpha(127, 127, 127, $alpha); -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, 80, $bg); - - my $used_height = @lines * 10; - - if ($used_height > 72) { - $used_height = 72; - } - - if ($used_height) { - $used_height += 8; - $im->filledRectangle(0, 0, 200, $used_height, $white); - $im->rectangle(0, 0, 200, $used_height, $gray); - } - - 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'); -} diff --git a/bin/vwrap b/bin/vwrap new file mode 100755 index 0000000..7015d17 --- /dev/null +++ b/bin/vwrap @@ -0,0 +1,69 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; +use autodie; + +use GD; +use Getopt::Std; +use IPC::Run qw(run); + +my %opts; + +getopts('a:cfgh:o:w:C:', \%opts); + +my $alpha = $opts{a} // 0; +my $width = $opts{w} // 200; +my $height = $opts{h} // 80; + +my $outfile = $opts{o} // '/tmp/vwrap.png'; + +my $im = GD::Image->new($width, $height); +$im->saveAlpha(1); + +my $white = $im->colorAllocateAlpha(255, 255, 255, $alpha); +my $gray = $im->colorAllocateAlpha(127, 127, 127, $alpha); +my $fg = $im->colorAllocateAlpha( 0, 0, 0, $alpha); +my $bg = $im->colorAllocateAlpha( 0, 0, 0, 127); +my $buf; + +if ($opts{'C'}) { + $fg = $im->colorAllocateAlpha(split(qr{,}, $opts{'C'}), $alpha); +} + +run(\@ARGV, \undef, \$buf, \*STDERR); + +my @lines = split(/\n/, $buf); + +if ($opts{'c'}) { + say join("\n", @lines); +} +elsif ($opts{'g'}) { + $im->filledRectangle(0, 0, $width, $height, $bg); + + my $used_height = @lines * 10; + + if ($used_height > $height) { + $used_height = $height; + } + + if ($used_height) { + $used_height += 8; + $im->filledRectangle(0, 0, $width, $used_height, $white); + $im->rectangle(0, 0, $width, $used_height, $gray); + } + + for my $i (0 .. $#lines) { + $lines[$i] =~ s{\t}{}; + $im->string(gdSmallFont, 2, 2 + (10 * $i), $lines[$i], $fg); + } + + open(my $out_fh, '>', $outfile); + binmode $out_fh; + print $out_fh $im->png(); + close($out_fh); +} + +if ($opts{'f'}) { + exec('feh', $outfile); +} -- cgit v1.2.3