Use Immich's orientation-aware dimensions instead of exif dimensions
This commit is contained in:
@@ -58,13 +58,12 @@ const EXIF_RULES: FieldRule[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
flag: 'dimensions',
|
flag: 'dimensions',
|
||||||
emit: (out, info) => {
|
emit: (out, _info, asset) => {
|
||||||
if (info.exifImageWidth && info.exifImageHeight) {
|
// Immich has already applied EXIF orientation to the asset-level
|
||||||
out.width = info.exifImageWidth
|
// dimensions; `exifImage*` holds the raw stored size.
|
||||||
out.height = info.exifImageHeight
|
if (asset.width && asset.height) {
|
||||||
if (info.orientation && ['5', '6', '7', '8'].includes(info.orientation)) {
|
out.width = asset.width
|
||||||
[out.width, out.height] = [out.height, out.width]
|
out.height = asset.height
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -55,9 +55,14 @@ describe('buildAssetMetadata', () => {
|
|||||||
expect(meta.exif?.city).toBeUndefined()
|
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', () => {
|
it('reports dimensions in display orientation', () => {
|
||||||
setConfig({ ipp: { showMetadata: { exif: { dimensions: true } } } })
|
setConfig({ ipp: { showMetadata: { exif: { dimensions: true } } } })
|
||||||
const photo = asset()
|
const photo = asset()
|
||||||
|
photo.width = 3000
|
||||||
|
photo.height = 4000
|
||||||
photo.exifInfo!.exifImageWidth = 4000
|
photo.exifInfo!.exifImageWidth = 4000
|
||||||
photo.exifInfo!.exifImageHeight = 3000
|
photo.exifInfo!.exifImageHeight = 3000
|
||||||
photo.exifInfo!.orientation = '6'
|
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', () => {
|
it('returns description when a description surface is enabled', () => {
|
||||||
setConfig({ ipp: { showMetadata: { description: { sidebar: true } } } })
|
setConfig({ ipp: { showMetadata: { description: { sidebar: true } } } })
|
||||||
const meta = buildAssetMetadata(asset(), share())
|
const meta = buildAssetMetadata(asset(), share())
|
||||||
|
|||||||
Reference in New Issue
Block a user