diff options
author | Graeme Porteous <graeme@rgbp.co.uk> | 2019-12-18 16:16:54 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2020-01-27 16:00:41 +0000 |
commit | 2d6af993630d9e43594975e093507ee62ed53b97 (patch) | |
tree | 514de24dd76344d88dcd5bf6494dbda519e90ebe /perllib/FixMyStreet/App/Model/PhotoSet.pm | |
parent | 856ae6bed192345249df8569518a4ecd074b3dc0 (diff) |
Add per report OpenGraph images
Includes a bit of refactoring of PhotoSet::get_image_data to make
it easier to call subsequent methods on the photo object. We then
do this to get the width and height.
Also adds width/height attributes to FixMyStreet::ImageMagick
Attributes are updated every time the image is transformed and before
the as_blob data, which also undefs the image, is returned so it always
present for subsequent calls.
Fixes #2394.
Diffstat (limited to 'perllib/FixMyStreet/App/Model/PhotoSet.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Model/PhotoSet.pm | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm index c9f1c48a1..76a287e71 100644 --- a/perllib/FixMyStreet/App/Model/PhotoSet.pm +++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm @@ -192,7 +192,6 @@ sub get_image_data { my $image = $self->get_raw_image( $num ) or return; - my $photo = $image->{data}; my $size = $args{size}; @@ -201,19 +200,24 @@ sub get_image_data { return $image; } - my $im = FixMyStreet::ImageMagick->new(blob => $photo); + my $im = FixMyStreet::ImageMagick->new(blob => $image->{data}); + my $photo; if ( $size eq 'tn' ) { - $photo = $im->shrink('x100')->as_blob; + $photo = $im->shrink('x100'); } elsif ( $size eq 'fp' ) { - $photo = $im->crop->as_blob; + $photo = $im->crop; + } elsif ( $size eq 'og' ) { + $photo = $im->crop('1200x630'); } elsif ( $size eq 'full' ) { - # do nothing + $photo = $im } else { - $photo = $im->shrink($args{default} || '250x250')->as_blob; + $photo = $im->shrink($args{default} || '250x250'); } return { - data => $photo, + data => $photo->as_blob, + width => $photo->width, + height => $photo->height, content_type => $image->{content_type}, }; } |