Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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