From 9e817943acfb4c8a8b5824cd7a87a21a654a7fb1 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Thu, 7 Apr 2016 15:57:42 -0700 Subject: integrates photo uploading in the main note interface Quill corrects the photo rotation based on exif data since iOS tends to take landscape photos and set the rotation bit when holding it in portrait mode. --- lib/helpers.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/helpers.php b/lib/helpers.php index c606dab..3939708 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -323,3 +323,26 @@ function validate_photo(&$file) { return $e->getMessage(); } } + +// Reads the exif rotation data and actually rotates the photo. +// 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); + } +} + -- cgit v1.2.3