summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-05-15 10:38:04 +0200
committerGitHub <noreply@github.com>2024-05-15 10:38:04 +0200
commit8898191d15dbb80c69449ffdca46612eb1660792 (patch)
treeffa26d9bc488bd82e29a4581f9749db8781c32ce
parent4f532ac0215d2bd540fe48d92f1bc55c8d763386 (diff)
parent2f84ccc627f86e2772879edb554ff5a1d02412d3 (diff)
Merge pull request #2478 from nextcloud/backport/2474/stable28v28.0.6rc1
-rw-r--r--lib/AppInfo/Application.php1
-rw-r--r--lib/Listener/SizeMetadataProvider.php16
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 36d4c8bc..655b5758 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -92,6 +92,7 @@ class Application extends App implements IBootstrap {
// Metadata
$context->registerEventListener(MetadataLiveEvent::class, ExifMetadataProvider::class);
$context->registerEventListener(MetadataBackgroundEvent::class, ExifMetadataProvider::class);
+ // SizeMetadataProvider optionally depends on ExifMetadataProvider, so it has to be registered afterwards
$context->registerEventListener(MetadataLiveEvent::class, SizeMetadataProvider::class);
$context->registerEventListener(MetadataBackgroundEvent::class, SizeMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, OriginalDateTimeMetadataProvider::class);
diff --git a/lib/Listener/SizeMetadataProvider.php b/lib/Listener/SizeMetadataProvider.php
index ce01cbf8..4ce62981 100644
--- a/lib/Listener/SizeMetadataProvider.php
+++ b/lib/Listener/SizeMetadataProvider.php
@@ -67,6 +67,22 @@ class SizeMetadataProvider implements IEventListener {
return;
}
+ // The image might have a rotation stored in the EXIF data.
+ // If that is the case and the rotation is 90/270 degrees the width and height need to be swapped.
+ // This is necessary because the clients will take the rotation into account when displaying the image.
+ if ($event->getMetadata()->hasKey('photos-ifd0')) {
+ $ifd0 = $event->getMetadata()->getArray('photos-ifd0');
+ if (array_key_exists('Orientation', $ifd0)) {
+ /** @var int $orientation */
+ $orientation = $ifd0['Orientation'];
+
+ // https://exiftool.org/TagNames/EXIF.html
+ if ($orientation >= 5) {
+ $size = [$size[1], $size[0]];
+ }
+ }
+ }
+
$event->getMetadata()->setArray('photos-size', [
'width' => $size[0],
'height' => $size[1],