diff options
author | Aaron Parecki <aaron@parecki.com> | 2016-04-07 15:57:42 -0700 |
---|---|---|
committer | Aaron Parecki <aaron@parecki.com> | 2016-04-07 15:57:42 -0700 |
commit | 9e817943acfb4c8a8b5824cd7a87a21a654a7fb1 (patch) | |
tree | dc16ffe24f3174d2a78ae46fdc26b889c2e5d9f5 /lib/helpers.php | |
parent | 1e1039846dc202931bfa822bd52d7cdf451b2d22 (diff) |
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.
Diffstat (limited to 'lib/helpers.php')
-rw-r--r-- | lib/helpers.php | 23 |
1 files changed, 23 insertions, 0 deletions
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); + } +} + |