fix(web): use irot/imir tags for HEIF Orientation (#27820)

* fix(web): use irot/imir tags for HEIF Orientation

* ignore Exif Orientation for HEIF images per MIAF standard compliance

* add Rotation and Mirroring to exiftool numericTags

* add isHeifBasedImage function to detect HEIF-based image extensions

* add getHeifBasedOrientation method to map irot/imir tags to ExifOrientation

* removed mirroring, simplified code

* Removed "Based" in "heifBased"

---------

Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
joojoooo
2026-06-08 09:33:28 -04:00
committed by GitHub
co-authored by Jason Rasmussen
parent 12d344efe0
commit 164cda87a3
3 changed files with 38 additions and 1 deletions
+31
View File
@@ -616,6 +616,17 @@ export class MetadataService extends BaseService {
// never use duration from sidecar
delete sidecarTags?.Duration;
// don't use Exif Orientation for HEIF based images, it's usually missing or invalid.
// prefer irot (ExifTool QuickTime:Rotation) mapped to ExifOrientation.
if (mimeTypes.isHeifImage(asset.originalPath)) {
const orientation = this.getHeifOrientation(mediaTags);
if (orientation === null) {
delete mediaTags.Orientation;
} else {
mediaTags.Orientation = orientation;
}
}
return {
tags: { ...mediaTags, ...videoResult?.tags, ...sidecarTags },
audio: videoResult?.audio,
@@ -1110,4 +1121,24 @@ export class MetadataService extends BaseService {
return { tags, audio, video, packets, format };
}
private getHeifOrientation(exifTags: ImmichTags): ExifOrientation | null {
// https://exiftool.org/TagNames/QuickTime.html#ItemPropCont
const rotation = typeof exifTags.Rotation === 'number' ? exifTags.Rotation : undefined;
switch (rotation) {
case 0: {
return ExifOrientation.Horizontal;
}
case 1: {
return ExifOrientation.Rotate270CW;
}
case 2: {
return ExifOrientation.Rotate180;
}
case 3: {
return ExifOrientation.Rotate90CW;
}
}
return null;
}
}