blob: 17514f1958371951988dade0e9688504025b505d (
plain)
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
42
43
44
45
46
|
package Utils::Photo;
use Image::Size;
=head2 get_photo_params
Returns a hashref of details of any attached photo (the first, if multiple
ones) for use in templates. Hashref contains height, width and url keys.
=cut
sub get_photo_params {
my ($self, $key) = @_;
return {} unless $self->photo;
$key = ($key eq 'id') ? '' : "/$key";
my $pre = "/photo$key/" . $self->id;
my $post = '.jpeg';
my $photo = {};
if ($self->can('get_photoset')) {
my $data = $self->get_photoset()->get_raw_image_data(0);
my $fileid = $data->[0];
$post .= '?' . $fileid;
$photo->{url_full} = "$pre.full$post";
} elsif (length($self->photo) == 40) {
$post .= '?' . $self->photo;
$photo->{url_full} = "$pre.full$post";
# XXX Can't use size here because {url} (currently 250px height) may be
# being used, but at this point it doesn't yet exist to find the width
# $str = FixMyStreet->config('UPLOAD_DIR') . $self->photo . '.jpeg';
} else {
my $str = \$self->photo;
( $photo->{width}, $photo->{height} ) = Image::Size::imgsize( $str );
}
$photo->{url} = "$pre$post";
$photo->{url_tn} = "$pre.tn$post";
$photo->{url_fp} = "$pre.fp$post";
return $photo;
}
1;
|