From 998db0cb90b416f92d78edfd67bdd493cbfae62a Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Wed, 7 Nov 2018 13:20:28 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20#90=20=E2=80=94=20catch=20Image::Magick?= =?UTF-8?q?=20problems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Lutim/Controller/Image.pm | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Lutim/Controller/Image.pm b/lib/Lutim/Controller/Image.pm index e3bbc62..5658513 100644 --- a/lib/Lutim/Controller/Image.pm +++ b/lib/Lutim/Controller/Image.pm @@ -401,25 +401,25 @@ sub add { my ($width, $height); if ($im_loaded && $mediatype ne 'image/svg+xml' && $mediatype !~ m#image/(x-)?xcf# && $mediatype ne 'image/webp') { # ImageMagick don't work in Debian with svg (for now?) my $im = Image::Magick->new; - $im->BlobToImage($upload->slurp); + if($im->BlobToImage($upload->slurp)) { + # Automatic rotation from EXIF tag + $im->AutoOrient(); - # Automatic rotation from EXIF tag - $im->AutoOrient(); + # Update the uploaded file with it's auto-rotated clone + my $asset = Mojo::Asset::Memory->new->add_chunk($im->ImageToBlob()); + $upload->asset($asset); - # Update the uploaded file with it's auto-rotated clone - my $asset = Mojo::Asset::Memory->new->add_chunk($im->ImageToBlob()); - $upload->asset($asset); + # Create the thumbnail + $width = $im->Get('width'); + $height = $im->Get('height'); + $im->Resize(geometry=>'x85'); - # Create the thumbnail - $width = $im->Get('width'); - $height = $im->Get('height'); - $im->Resize(geometry=>'x85'); - - $thumb = 'data:'.$mediatype.';base64,'; - if ($mediatype eq 'image/gif') { - $thumb .= b64_encode $im->[0]->ImageToBlob(); - } else { - $thumb .= b64_encode $im->ImageToBlob(); + $thumb = 'data:'.$mediatype.';base64,'; + if ($mediatype eq 'image/gif') { + $thumb .= b64_encode $im->[0]->ImageToBlob(); + } else { + $thumb .= b64_encode $im->ImageToBlob(); + } } }