aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-16 11:45:30 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-16 11:45:30 +0100
commitd963cf63b2d94e87c4ccd33051235aa72c14b2e7 (patch)
treec41744476055f55f1812e164a0e0686c5b5912d0 /perllib/FixMyStreet/App
parent3aeece7e98b7a1853500c473ee2d8a7785a72b78 (diff)
quick implementation of photo display controller
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm79
1 files changed, 79 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
new file mode 100644
index 000000000..64a4aef93
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -0,0 +1,79 @@
+package FixMyStreet::App::Controller::Photo;
+use Moose;
+use namespace::autoclean;
+
+BEGIN {extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+FixMyStreet::App::Controller::Photo - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+Display a photo
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+
+ my $id = $c->req->param('id');
+ my $comment = $c->req->param('c');
+ return unless ( $id || $comment );
+
+ my $photo;
+
+ if ( $comment ) {
+ # FIXME implement comment photos
+ return;
+ } else {
+ $photo = $c->model('DB::Problem')->find( {id => $id, state => 'confirmed' } );
+ }
+
+ return unless $photo;
+
+ $photo = $photo->photo;
+ if ( $c->req->param('tn' ) ) {
+ $photo = _resize( $photo, 'x100' );
+ } elsif ( 0 ) { # emptyhomes
+ $photo = _resize( $photo, '195x' );
+ }
+
+ print $photo;
+}
+
+sub _resize {
+ my ($photo, $size) = @_;
+ use Image::Magick;
+ my $image = Image::Magick->new;
+ $image->BlobToImage($photo);
+ my $err = $image->Scale(geometry => "$size>");
+ throw Error::Simple("resize failed: $err") if "$err";
+ my @blobs = $image->ImageToBlob();
+ undef $image;
+ return $blobs[0];
+}
+
+=head1 AUTHOR
+
+Struan Donald
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;