Skip to content

Commit

Permalink
Merge pull request #2478 from nextcloud/backport/2474/stable28
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored May 15, 2024
2 parents 4f532ac + 2f84ccc commit 8898191
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function register(IRegistrationContext $context): void {
// 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);
Expand Down
16 changes: 16 additions & 0 deletions lib/Listener/SizeMetadataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public function handle(Event $event): void {
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],
Expand Down

0 comments on commit 8898191

Please sign in to comment.