From 202a7876ec508fd70385497c1508b33aeb367c67 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 24 Feb 2017 16:40:56 -0800 Subject: nicer photo uploading experience --- lib/helpers.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/helpers.php b/lib/helpers.php index d932e67..b7ae78d 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -363,21 +363,23 @@ function validate_photo(&$file) { // Only does anything if the exif library is loaded, otherwise is a noop. function correct_photo_rotation($filename) { if(class_exists('IMagick')) { - $image = new IMagick($filename); - $orientation = $image->getImageOrientation(); - switch($orientation) { - case IMagick::ORIENTATION_BOTTOMRIGHT: - $image->rotateImage(new ImagickPixel('#00000000'), 180); - break; - case IMagick::ORIENTATION_RIGHTTOP: - $image->rotateImage(new ImagickPixel('#00000000'), 90); - break; - case IMagick::ORIENTATION_LEFTBOTTOM: - $image->rotateImage(new ImagickPixel('#00000000'), -90); - break; - } - $image->setImageOrientation(IMagick::ORIENTATION_TOPLEFT); - $image->writeImage($filename); + try { + $image = new IMagick($filename); + $orientation = $image->getImageOrientation(); + switch($orientation) { + case IMagick::ORIENTATION_BOTTOMRIGHT: + $image->rotateImage(new ImagickPixel('#00000000'), 180); + break; + case IMagick::ORIENTATION_RIGHTTOP: + $image->rotateImage(new ImagickPixel('#00000000'), 90); + break; + case IMagick::ORIENTATION_LEFTBOTTOM: + $image->rotateImage(new ImagickPixel('#00000000'), -90); + break; + } + $image->setImageOrientation(IMagick::ORIENTATION_TOPLEFT); + $image->writeImage($filename); + } catch(Exception $e){} } } -- cgit v1.2.3