blob: 2799c75366e1b3d59b0ccb0b3c8065dbec1c87bf (
plain) (
blame)
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
|
#!/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, '',
filename => 'cosa.png'});
|