summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-10-26 21:36:33 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-10-26 21:37:11 +0200
commitb05fe45d520a8df309897626ad109a4daf64ed83 (patch)
treedb1dde9e86038503142af2888fffa37adfa6561c
parentb98dfaccd96fb9b0da13bc59f55ed9b61cbbd528 (diff)
downloadnextcloud-server-b05fe45d520a8df309897626ad109a4daf64ed83.tar.gz
nextcloud-server-b05fe45d520a8df309897626ad109a4daf64ed83.zip
Fix avatar on exif rotated images
Fixes #1928 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--core/Controller/AvatarController.php1
-rw-r--r--lib/private/legacy/image.php27
2 files changed, 28 insertions, 0 deletions
diff --git a/core/Controller/AvatarController.php b/core/Controller/AvatarController.php
index c6f320dd0fe..5e3d563cf2c 100644
--- a/core/Controller/AvatarController.php
+++ b/core/Controller/AvatarController.php
@@ -237,6 +237,7 @@ class AvatarController extends Controller {
try {
$image = new \OC_Image();
$image->loadFromData($content);
+ $image->readExif($content);
$image->fixOrientation();
if ($image->valid()) {
diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php
index fee1a805c40..5403cccd026 100644
--- a/lib/private/legacy/image.php
+++ b/lib/private/legacy/image.php
@@ -54,6 +54,8 @@ class OC_Image implements \OCP\IImage {
private $fileInfo;
/** @var \OCP\ILogger */
private $logger;
+ /** @var array */
+ private $exif;
/**
* Get mime type for an image file.
@@ -347,6 +349,10 @@ class OC_Image implements \OCP\IImage {
* @return int The orientation or -1 if no EXIF data is available.
*/
public function getOrientation() {
+ if ($this->exif !== null) {
+ return $this->exif['Orientation'];
+ }
+
if ($this->imageType !== IMAGETYPE_JPEG) {
$this->logger->debug('OC_Image->fixOrientation() Image is not a JPEG.', array('app' => 'core'));
return -1;
@@ -370,9 +376,30 @@ class OC_Image implements \OCP\IImage {
if (!isset($exif['Orientation'])) {
return -1;
}
+ $this->exif = $exif;
return $exif['Orientation'];
}
+ public function readExif($data) {
+ if (!is_callable('exif_read_data')) {
+ $this->logger->debug('OC_Image->fixOrientation() Exif module not enabled.', array('app' => 'core'));
+ return;
+ }
+ if (!$this->valid()) {
+ $this->logger->debug('OC_Image->fixOrientation() No image loaded.', array('app' => 'core'));
+ return;
+ }
+
+ $exif = @exif_read_data('data://image/jpeg;base64,' . base64_encode($data));
+ if (!$exif) {
+ return;
+ }
+ if (!isset($exif['Orientation'])) {
+ return;
+ }
+ $this->exif = $exif;
+ }
+
/**
* (I'm open for suggestions on better method name ;)
* Fixes orientation based on EXIF data.