Merge pull request #2474 from nextcloud/fix/size-metadata-provider/rotation

This commit is contained in:
John Molakvoæ 2024-05-14 18:25:37 +02:00 committed by GitHub
commit f85947fdc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -75,6 +75,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);

View File

@ -53,6 +53,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],