From 95d45dde0fb7c95b7845d752d2c57cc9d7b8d456 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 12 Apr 2021 09:56:02 +1000 Subject: [PATCH] * LDV::Filebin : threat djvu and unsupported images as binary --- lib/LDV/Filebin.pm | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/LDV/Filebin.pm b/lib/LDV/Filebin.pm index 39a7cb2..c64278e 100644 --- a/lib/LDV/Filebin.pm +++ b/lib/LDV/Filebin.pm @@ -95,18 +95,20 @@ sub save { bytes => $conf->{image_maxmem}, ); # query image - my $image = Imager->new(file => $upload->asset->path) - or die(Imager->errstr() . "\n"); - $file->{ftype} = 'i'; - $file->{fext} = $image->tags(name => 'i_format'), - $file->{res_w} = $image->getwidth, - $file->{res_h} = $image->getheight, - # make thumb - my ($th_w, $th_h) = ($conf->{thumbs_size} =~ m/(\d+)x(\d+)/oi); - my $thumb = $image->scale(xpixels => $th_w, ypixels => $th_h, type => 'min'); - my $path = $self->_file_path("${time}_tn", $conf->{thumbs_ext}, 'fullpath'); - $thumb->write(file => $path) - or die $thumb->errstr; + if (my $image = Imager->new(file => $upload->asset->path)) { + $file->{ftype} = 'i'; + $file->{fext} = $image->tags(name => 'i_format'), + $file->{res_w} = $image->getwidth, + $file->{res_h} = $image->getheight, + # make thumb + my ($th_w, $th_h) = ($conf->{thumbs_size} =~ m/(\d+)x(\d+)/oi); + my $thumb = $image->scale(xpixels => $th_w, ypixels => $th_h, type => 'min'); + my $path = $self->_file_path("${time}_tn", $conf->{thumbs_ext}, 'fullpath'); + $thumb->write(file => $path) + or die $thumb->errstr; + } else { + # unsupported image, djvu, ... + } } elsif ($file->{fmime} =~ m{^video/}o) { $file->{ftype} = 'v'; } elsif ($file->{fmime} =~ m{^audio/}o) {