summaryrefslogtreecommitdiff
path: root/lib/helpers.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/helpers.php')
-rw-r--r--lib/helpers.php23
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);
+ }
+}
+