aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm39
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm5
2 files changed, 41 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 3e71cb0bd..c14b7e9b1 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use FixMyStreet::Geocode;
use Encode;
+use Image::Magick;
use Sort::Key qw(keysort);
use List::MoreUtils qw(uniq);
use HTML::Entities;
@@ -13,6 +14,7 @@ use mySociety::MaPit;
use Path::Class;
use Utils;
use mySociety::EmailUtil;
+use mySociety::TempFiles;
=head1 NAME
@@ -737,7 +739,7 @@ sub process_photo_upload : Private {
# convert the photo into a blob (also resize etc)
my $photo_blob =
- eval { Page::process_photo( $upload->fh, $args->{rotate_photo} ) };
+ eval { _process_photo( $upload->fh, $args->{rotate_photo} ) };
if ( my $error = $@ ) {
my $format = _(
"That image doesn't appear to have uploaded correctly (%s), please try again."
@@ -987,6 +989,41 @@ sub redirect_to_around : Private {
return $c->res->redirect($around_uri);
}
+sub _process_photo {
+ my $fh = shift;
+ my $import = shift;
+
+ my $blob = join('', <$fh>);
+ close $fh;
+ my ($handle, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
+ print $handle $blob;
+ close $handle;
+
+ my $photo = Image::Magick->new;
+ my $err = $photo->Read($filename);
+ unlink $filename;
+ throw Error::Simple("read failed: $err") if "$err";
+ $err = $photo->Scale(geometry => "250x250>");
+ throw Error::Simple("resize failed: $err") if "$err";
+ my @blobs = $photo->ImageToBlob();
+ undef $photo;
+ $photo = $blobs[0];
+ return $photo unless $import; # Only check orientation for iPhone imports at present
+
+ # Now check if it needs orientating
+ ($fh, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
+ print $fh $photo;
+ close $fh;
+ my $out = `jhead -se -autorot $filename`;
+ if ($out) {
+ open(FP, $filename) or throw Error::Simple($!);
+ $photo = join('', <FP>);
+ close FP;
+ }
+ unlink $filename;
+ return $photo;
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index b5f6e341d..5b20e286b 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -8,6 +8,7 @@ use mySociety::Locale;
use mySociety::Web qw(ent);
use FixMyStreet;
use CrossSell;
+use Utils;
__PACKAGE__->config(
TEMPLATE_EXTENSION => '.html',
@@ -91,7 +92,7 @@ sub display_crosssell_advert {
return CrossSell::display_advert( $q, $email, $name, %data );
}
-=head2 Page::prettify_epoch
+=head2 Utils::prettify_epoch
[% pretty = prettify_epoch( $epoch, $short_bool ) %]
@@ -104,7 +105,7 @@ Return a pretty version of the epoch.
sub prettify_epoch {
my ( $self, $c, $epoch, $short_bool ) = @_;
- return Page::prettify_epoch( $epoch, $short_bool );
+ return Utils::prettify_epoch( $epoch, $short_bool );
}
=head2 add_links