aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-10-27 08:56:56 +0200
committerGitHub <noreply@github.com>2016-10-27 08:56:56 +0200
commit7cae758ef9fc2963fa8889dc448e54c1e2d1e71a (patch)
tree2c44e2c8fc47edfef110baf0cb6dfa4ab60fece8 /lib
parent9984eba7278685d5bb0017e971751af4130aa875 (diff)
parentb05fe45d520a8df309897626ad109a4daf64ed83 (diff)
downloadnextcloud-server-7cae758ef9fc2963fa8889dc448e54c1e2d1e71a.tar.gz
nextcloud-server-7cae758ef9fc2963fa8889dc448e54c1e2d1e71a.zip
Merge pull request #1930 from nextcloud/fix_avatars_exif
Fix avatar on exif rotated images
Diffstat (limited to 'lib')
-rw-r--r--lib/private/legacy/image.php27
1 files changed, 27 insertions, 0 deletions
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.