aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-07-19 13:00:56 +0100
committerDave Arter <davea@mysociety.org>2016-08-01 11:51:38 +0100
commitd8af894ea2fdc41f03b96220b8f7510eb54ce686 (patch)
tree623817e98a275dbae6073c364f73df16e8759d5b
parent14aaf6fafaa9aa8736f49851e95fa2c3c566c056 (diff)
Test for Image::Magick installation better.
(VERSION disappears in some recent version.)
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm1
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm1
-rw-r--r--perllib/FixMyStreet/App/Model/PhotoSet.pm14
3 files changed, 10 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 93e8f4b22..44a653d62 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -8,7 +8,6 @@ use Path::Class;
use POSIX qw(strftime strcoll);
use Digest::SHA qw(sha1_hex);
use mySociety::EmailUtil qw(is_valid_email);
-use if !$ENV{TRAVIS}, 'Image::Magick';
use DateTime::Format::Strptime;
use List::Util 'first';
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index 2734491fa..2302322bf 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -8,7 +8,6 @@ use JSON::MaybeXS;
use File::Path;
use File::Slurp;
use FixMyStreet::App::Model::PhotoSet;
-use if !$ENV{TRAVIS}, 'Image::Magick';
=head1 NAME
diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm
index 1c8a86e3a..487786a3b 100644
--- a/perllib/FixMyStreet/App/Model/PhotoSet.pm
+++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm
@@ -4,7 +4,13 @@ package FixMyStreet::App::Model::PhotoSet;
use Moose;
use Path::Tiny 'path';
-use if !$ENV{TRAVIS}, 'Image::Magick';
+
+my $IM = eval {
+ require Image::Magick;
+ Image::Magick->import;
+ 1;
+};
+
use Scalar::Util 'openhandle', 'blessed';
use Digest::SHA qw(sha1_hex);
use Image::Size;
@@ -318,7 +324,7 @@ sub rotate_image {
sub _rotate_image {
my ($photo, $direction) = @_;
- return $photo unless $Image::Magick::VERSION;
+ return $photo unless $IM;
my $image = Image::Magick->new;
$image->BlobToImage($photo);
my $err = $image->Rotate($direction);
@@ -332,7 +338,7 @@ sub _rotate_image {
# Shrinks a picture to the specified size, but keeping in proportion.
sub _shrink {
my ($photo, $size) = @_;
- return $photo unless $Image::Magick::VERSION;
+ return $photo unless $IM;
my $image = Image::Magick->new;
$image->BlobToImage($photo);
my $err = $image->Scale(geometry => "$size>");
@@ -346,7 +352,7 @@ sub _shrink {
# Shrinks a picture to 90x60, cropping so that it is exactly that.
sub _crop {
my ($photo) = @_;
- return $photo unless $Image::Magick::VERSION;
+ return $photo unless $IM;
my $image = Image::Magick->new;
$image->BlobToImage($photo);
my $err = $image->Resize( geometry => "90x60^" );