From 628de40b877974eb553e0910753f2d4cd983d9de Mon Sep 17 00:00:00 2001 From: M Somerville Date: Fri, 13 Nov 2020 14:24:54 +0000 Subject: Add GitHub Actions. We now have Image::Magick, so make sure that is handled better. --- perllib/FixMyStreet/App/Model/PhotoSet.pm | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'perllib/FixMyStreet/App/Model/PhotoSet.pm') diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm index 76a287e71..85e457856 100644 --- a/perllib/FixMyStreet/App/Model/PhotoSet.pm +++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm @@ -8,6 +8,7 @@ use Scalar::Util 'openhandle', 'blessed'; use Image::Size; use IPC::Cmd qw(can_run); use IPC::Open3; +use Try::Tiny; use FixMyStreet; use FixMyStreet::ImageMagick; @@ -149,7 +150,9 @@ has ids => ( # Arrayref of $fileid tuples (always, so post upload/raw data proc } # we have an image we can use - save it to storage - $photo_blob = FixMyStreet::ImageMagick->new(blob => $photo_blob)->shrink('2048x2048')->as_blob; + $photo_blob = try { + FixMyStreet::ImageMagick->new(blob => $photo_blob)->shrink('2048x2048')->as_blob; + } catch { $photo_blob }; return $self->storage->store_photo($photo_blob); } @@ -201,18 +204,20 @@ sub get_image_data { } my $im = FixMyStreet::ImageMagick->new(blob => $image->{data}); - my $photo; - if ( $size eq 'tn' ) { - $photo = $im->shrink('x100'); - } elsif ( $size eq 'fp' ) { - $photo = $im->crop; - } elsif ( $size eq 'og' ) { - $photo = $im->crop('1200x630'); - } elsif ( $size eq 'full' ) { - $photo = $im - } else { - $photo = $im->shrink($args{default} || '250x250'); - } + my $photo = try { + if ( $size eq 'tn' ) { + $im->shrink('x100'); + } elsif ( $size eq 'fp' ) { + $im->crop; + } elsif ( $size eq 'og' ) { + $im->crop('1200x630'); + } elsif ( $size eq 'full' ) { + $im + } else { + $im->shrink($args{default} || '250x250'); + } + }; + return unless $photo; return { data => $photo->as_blob, -- cgit v1.2.3