diff --git a/src/backend/model/threading/MetadataLoader.ts b/src/backend/model/threading/MetadataLoader.ts index ec2789d3..a195faeb 100644 --- a/src/backend/model/threading/MetadataLoader.ts +++ b/src/backend/model/threading/MetadataLoader.ts @@ -191,7 +191,6 @@ export class MetadataLoader { exif.tags.CreateDate || exif.tags.ModifyDate) * 1000; } - if (exif.imageSize) { metadata.size = { width: exif.imageSize.width, @@ -205,6 +204,14 @@ export class MetadataLoader { width: exif.tags.RelatedImageWidth, height: exif.tags.RelatedImageHeight, }; + }else if ( + exif.tags.ImageWidth && + exif.tags.ImageHeight + ) { + metadata.size = { + width: exif.tags.ImageWidth, + height: exif.tags.ImageHeight, + }; } else { const info = imageSize(fullPath); metadata.size = {width: info.width, height: info.height}; diff --git a/test/backend/assets/imageSizeError.jpg b/test/backend/assets/imageSizeError.jpg new file mode 100644 index 00000000..e0c24fe1 Binary files /dev/null and b/test/backend/assets/imageSizeError.jpg differ diff --git a/test/backend/assets/imageSizeError.json b/test/backend/assets/imageSizeError.json new file mode 100644 index 00000000..3c6842f1 --- /dev/null +++ b/test/backend/assets/imageSizeError.json @@ -0,0 +1,16 @@ +{ + "cameraData": { + "ISO": 160, + "exposure": 0.000537, + "fStop": 1.7, + "focalLength": 4.28, + "make": "Realme", + "model": "realme 3 Pro" + }, + "creationDate": 1654876257000, + "fileSize": 76736, + "size": { + "height": 2128, + "width": 4608 + } +} diff --git a/test/backend/unit/model/threading/MetaDataLoader.spec.ts b/test/backend/unit/model/threading/MetaDataLoader.spec.ts index f3859c1b..0b475873 100644 --- a/test/backend/unit/model/threading/MetaDataLoader.spec.ts +++ b/test/backend/unit/model/threading/MetaDataLoader.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ import {expect} from 'chai'; import {MetadataLoader} from '../../../../../src/backend/model/threading/MetadataLoader'; import {Utils} from '../../../../../src/common/Utils'; @@ -122,6 +123,12 @@ describe('MetadataLoader', () => { expect(Utils.clone(data)).to.be.deep.equal(expected); }); + it('should load jpg with provided ImageWidth but missing imageSize', async () => { + const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/imageSizeError.jpg')); + const expected = require(path.join(__dirname, '/../../../assets/imageSizeError.json')); + expect(Utils.clone(data)).to.be.deep.equal(expected); + }); + it('should load mp4', async () => { const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video.mp4'));