diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-02-05 17:01:41 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-02-05 18:12:49 +0000 |
commit | 6bc3566f0281f4aede0e11e8ab5e21476bc0b674 (patch) | |
tree | 6ec8384cf90bf64d719fb9ce77d69b5146c743a7 | |
parent | 46128a0f1998b01b6d698a22c8811f4898b69b0f (diff) |
Have code fallback to Image::Size if no jhead.
Don't bother installing it on Travis.
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 7 |
2 files changed, 6 insertions, 3 deletions
diff --git a/.travis.yml b/.travis.yml index d2579b5c7..b162c4c06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,6 @@ env: - secure: "qW+WCgAF68itADxcbcq+nCnKx3vf3GX73HMfjfbkFFUsYmIR+ZaJ9yQMnGJwxIpCHTWLAeqyx4KO8N8T3GmNdKYzIMZemOzp4ED29YC31QOQeq1CwNp2hD5sq/o47d2BzXWwMYNvNXfxz1K6r2c6EMPUtu8X3B8ExZq1RzSFdXs=" before_install: - - sudo apt-get update -qq - - sudo apt-get install -qq jhead - sudo locale-gen cy_GB.UTF-8 en_GB.UTF-8 nb_NO.UTF-8 de_CH.UTF-8 sv_SE.UTF-8 install: - .travis/install diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 09afabecf..d70be50e6 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -8,6 +8,7 @@ use DateTime::Format::HTTP; use Digest::SHA qw(sha1_hex); use File::Path; use File::Slurp; +use Image::Size; use Path::Class; use if !$ENV{TRAVIS}, 'Image::Magick'; @@ -181,7 +182,11 @@ sub process_photo_upload : Private { my $photo_blob = eval { my $filename = $upload->tempname; my $out = `jhead -se -autorot $filename 2>&1`; - die _("Please upload a JPEG image only"."\n") if $out =~ /Not JPEG:/; + unless (defined $out) { + my ($w, $h, $err) = Image::Size::imgsize($filename); + die _("Please upload a JPEG image only") . "\n" if !defined $w || $err ne 'JPG'; + } + die _("Please upload a JPEG image only") . "\n" if $out && $out =~ /Not JPEG:/; my $photo = $upload->slurp; return $photo; }; |