From fd42ab61daa4a86cb0230900167cc43fe52cb9e1 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Mon, 27 Jul 2026 09:53:05 +1200 Subject: [PATCH] Use Immich's orientation-aware dimensions instead of exif dimensions --- app/src/gallery/exif.ts | 13 ++++++------- app/tests/assetMetadata.test.ts | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/gallery/exif.ts b/app/src/gallery/exif.ts index 8d662d0..79d82c8 100644 --- a/app/src/gallery/exif.ts +++ b/app/src/gallery/exif.ts @@ -58,13 +58,12 @@ const EXIF_RULES: FieldRule[] = [ }, { flag: 'dimensions', - emit: (out, info) => { - if (info.exifImageWidth && info.exifImageHeight) { - out.width = info.exifImageWidth - out.height = info.exifImageHeight - if (info.orientation && ['5', '6', '7', '8'].includes(info.orientation)) { - [out.width, out.height] = [out.height, out.width] - } + emit: (out, _info, asset) => { + // Immich has already applied EXIF orientation to the asset-level + // dimensions; `exifImage*` holds the raw stored size. + if (asset.width && asset.height) { + out.width = asset.width + out.height = asset.height } } }, diff --git a/app/tests/assetMetadata.test.ts b/app/tests/assetMetadata.test.ts index 2700c8e..51139d1 100644 --- a/app/tests/assetMetadata.test.ts +++ b/app/tests/assetMetadata.test.ts @@ -55,9 +55,14 @@ describe('buildAssetMetadata', () => { expect(meta.exif?.city).toBeUndefined() }) + // Immich applies EXIF orientation before storing asset.width / asset.height, + // so a rotated photo reports portrait dimensions there while the exifImage* + // pair stays landscape. We must report the former. it('reports dimensions in display orientation', () => { setConfig({ ipp: { showMetadata: { exif: { dimensions: true } } } }) const photo = asset() + photo.width = 3000 + photo.height = 4000 photo.exifInfo!.exifImageWidth = 4000 photo.exifInfo!.exifImageHeight = 3000 photo.exifInfo!.orientation = '6' @@ -68,6 +73,15 @@ describe('buildAssetMetadata', () => { }) }) + it('omits dimensions when the asset has none', () => { + setConfig({ ipp: { showMetadata: { exif: { dimensions: true } } } }) + const photo = asset() + photo.exifInfo!.exifImageWidth = 4000 + photo.exifInfo!.exifImageHeight = 3000 + + expect(buildAssetMetadata(photo, share()).exif).toBeUndefined() + }) + it('returns description when a description surface is enabled', () => { setConfig({ ipp: { showMetadata: { description: { sidebar: true } } } }) const meta = buildAssetMetadata(asset(), share())