From 2b6c745ad845cfd9ca54fea915f0e19dc3a2c308 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Thu, 27 Feb 2020 16:13:39 +0100 Subject: Initial commit --- pegatino.pl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 pegatino.pl (limited to 'pegatino.pl') 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; +use MIME::Base64 qw; +use Image::Magick; +use File::Temp qw; +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, '' }); -- cgit v1.2.3