summaryrefslogtreecommitdiff
path: root/pegatino.pl
diff options
context:
space:
mode:
Diffstat (limited to 'pegatino.pl')
-rwxr-xr-xpegatino.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/pegatino.pl b/pegatino.pl
new file mode 100755
index 0000000..7ef2e61
--- /dev/null
+++ b/pegatino.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use JSON qw<encode_json>;
+use MIME::Base64 qw<encode_base64>;
+use Image::Magick;
+use File::Temp qw<tempfile>;
+use Data::Dumper;
+
+exit unless exists $ENV{'TGUTILS_TYPE'};
+exit unless $ENV{'TGUTILS_TYPE'} eq 'IMAGE';
+
+$/ = undef;
+binmode STDIN;
+my $origimg = <>;
+
+my ($origh, $origpath) = tempfile();
+
+binmode $origh;
+print $origh $origimg;
+close $origh;
+
+my $imagick = Image::Magick->new;
+$imagick->Read($origpath);
+$imagick->Resize(geometry => '512x512');
+
+my $newpath = $origpath . ".png";
+$imagick->Write($newpath);
+
+open(my $newh, "<", $newpath);
+binmode $newh;
+my $newimg = <$newh>;
+close $newh;
+
+unlink $origpath, $newpath;
+
+print encode_json({type => 'DOCUMENT', caption => 'Tenga, ayúdese', content => encode_base64 $newimg, '' });