diff --git a/src/backend/model/threading/MetadataLoader.ts b/src/backend/model/threading/MetadataLoader.ts index 48b22c72..64a1d258 100644 --- a/src/backend/model/threading/MetadataLoader.ts +++ b/src/backend/model/threading/MetadataLoader.ts @@ -154,9 +154,6 @@ export class MetadataLoader { } - if (exif.tags.Orientation) { - metadata.orientation = exif.tags.Orientation; - } if (exif.imageSize) { metadata.size = {width: exif.imageSize.width, height: exif.imageSize.height}; @@ -166,15 +163,6 @@ export class MetadataLoader { const info = imageSize(fullPath); metadata.size = {width: info.width, height: info.height}; } - if (OrientationTypes.BOTTOM_LEFT < metadata.orientation && - metadata.orientation <= OrientationTypes.LEFT_BOTTOM && - metadata.size.width > metadata.size.height) { - // noinspection JSSuspiciousNameCombination - const height = metadata.size.width; - // noinspection JSSuspiciousNameCombination - metadata.size.width = metadata.size.height; - metadata.size.height = height; - } } catch (err) { Logger.debug(LOG_TAG, 'Error parsing exif', fullPath, err); try { @@ -219,6 +207,17 @@ export class MetadataLoader { if (exif.Rating) { metadata.rating = parseInt(exif.Rating.value, 10); } + + if (exif.Orientation) { + metadata.orientation = parseInt(exif.Orientation.value, 10); + if (OrientationTypes.BOTTOM_LEFT < metadata.orientation) { + // noinspection JSSuspiciousNameCombination + const height = metadata.size.width; + // noinspection JSSuspiciousNameCombination + metadata.size.width = metadata.size.height; + metadata.size.height = height; + } + } if (Config.Client.Faces.enabled) { const faces: FaceRegion[] = []; if (exif.Regions && exif.Regions.value.RegionList && exif.Regions.value.RegionList.value) { diff --git a/test/backend/assets/orientation/Landscape.json b/test/backend/assets/orientation/Landscape.json new file mode 100644 index 00000000..09a58967 --- /dev/null +++ b/test/backend/assets/orientation/Landscape.json @@ -0,0 +1,9 @@ +{ + "creationDate": 1566424388000, + "fileSize": 349915, + "orientation": 1, + "size": { + "height": 1200, + "width": 1800 + } +} diff --git a/test/backend/assets/orientation/Landscape_0.jpg b/test/backend/assets/orientation/Landscape_0.jpg new file mode 100644 index 00000000..8518c82b Binary files /dev/null and b/test/backend/assets/orientation/Landscape_0.jpg differ diff --git a/test/backend/assets/orientation/Landscape_1.jpg b/test/backend/assets/orientation/Landscape_1.jpg new file mode 100644 index 00000000..fda18823 Binary files /dev/null and b/test/backend/assets/orientation/Landscape_1.jpg differ diff --git a/test/backend/assets/orientation/Landscape_2.jpg b/test/backend/assets/orientation/Landscape_2.jpg new file mode 100644 index 00000000..d2605f81 Binary files /dev/null and b/test/backend/assets/orientation/Landscape_2.jpg differ diff --git a/test/backend/assets/orientation/Landscape_3.jpg b/test/backend/assets/orientation/Landscape_3.jpg new file mode 100644 index 00000000..f5080523 Binary files /dev/null and b/test/backend/assets/orientation/Landscape_3.jpg differ diff --git a/test/backend/assets/orientation/Landscape_4.jpg b/test/backend/assets/orientation/Landscape_4.jpg new file mode 100644 index 00000000..d73dee8f Binary files /dev/null and b/test/backend/assets/orientation/Landscape_4.jpg differ diff --git a/test/backend/assets/orientation/Landscape_5.jpg b/test/backend/assets/orientation/Landscape_5.jpg new file mode 100644 index 00000000..975d8588 Binary files /dev/null and b/test/backend/assets/orientation/Landscape_5.jpg differ diff --git a/test/backend/assets/orientation/Landscape_6.jpg b/test/backend/assets/orientation/Landscape_6.jpg new file mode 100644 index 00000000..b579b7f9 Binary files /dev/null and b/test/backend/assets/orientation/Landscape_6.jpg differ diff --git a/test/backend/assets/orientation/Landscape_7.jpg b/test/backend/assets/orientation/Landscape_7.jpg new file mode 100644 index 00000000..b1e919cf Binary files /dev/null and b/test/backend/assets/orientation/Landscape_7.jpg differ diff --git a/test/backend/assets/orientation/Landscape_8.jpg b/test/backend/assets/orientation/Landscape_8.jpg new file mode 100644 index 00000000..c381db10 Binary files /dev/null and b/test/backend/assets/orientation/Landscape_8.jpg differ diff --git a/test/backend/assets/orientation/Portrait.json b/test/backend/assets/orientation/Portrait.json new file mode 100644 index 00000000..65fc1c9f --- /dev/null +++ b/test/backend/assets/orientation/Portrait.json @@ -0,0 +1,9 @@ +{ + "creationDate": 1566424388000, + "fileSize": 349915, + "orientation": 1, + "size": { + "height": 1800, + "width": 1200 + } +} diff --git a/test/backend/assets/orientation/Portrait_0.jpg b/test/backend/assets/orientation/Portrait_0.jpg new file mode 100644 index 00000000..aa9632e5 Binary files /dev/null and b/test/backend/assets/orientation/Portrait_0.jpg differ diff --git a/test/backend/assets/orientation/Portrait_1.jpg b/test/backend/assets/orientation/Portrait_1.jpg new file mode 100644 index 00000000..dcb57c53 Binary files /dev/null and b/test/backend/assets/orientation/Portrait_1.jpg differ diff --git a/test/backend/assets/orientation/Portrait_2.jpg b/test/backend/assets/orientation/Portrait_2.jpg new file mode 100644 index 00000000..8c3adf7a Binary files /dev/null and b/test/backend/assets/orientation/Portrait_2.jpg differ diff --git a/test/backend/assets/orientation/Portrait_3.jpg b/test/backend/assets/orientation/Portrait_3.jpg new file mode 100644 index 00000000..5a5544f2 Binary files /dev/null and b/test/backend/assets/orientation/Portrait_3.jpg differ diff --git a/test/backend/assets/orientation/Portrait_4.jpg b/test/backend/assets/orientation/Portrait_4.jpg new file mode 100644 index 00000000..9eb2a6a1 Binary files /dev/null and b/test/backend/assets/orientation/Portrait_4.jpg differ diff --git a/test/backend/assets/orientation/Portrait_5.jpg b/test/backend/assets/orientation/Portrait_5.jpg new file mode 100644 index 00000000..905169aa Binary files /dev/null and b/test/backend/assets/orientation/Portrait_5.jpg differ diff --git a/test/backend/assets/orientation/Portrait_6.jpg b/test/backend/assets/orientation/Portrait_6.jpg new file mode 100644 index 00000000..8fc576e0 Binary files /dev/null and b/test/backend/assets/orientation/Portrait_6.jpg differ diff --git a/test/backend/assets/orientation/Portrait_7.jpg b/test/backend/assets/orientation/Portrait_7.jpg new file mode 100644 index 00000000..cfa04d66 Binary files /dev/null and b/test/backend/assets/orientation/Portrait_7.jpg differ diff --git a/test/backend/assets/orientation/Portrait_8.jpg b/test/backend/assets/orientation/Portrait_8.jpg new file mode 100644 index 00000000..b2a50d6e Binary files /dev/null and b/test/backend/assets/orientation/Portrait_8.jpg differ diff --git a/test/backend/assets/broken_orientation_exif.jpg b/test/backend/assets/orientation/broken_orientation_exif.jpg similarity index 100% rename from test/backend/assets/broken_orientation_exif.jpg rename to test/backend/assets/orientation/broken_orientation_exif.jpg diff --git a/test/backend/assets/broken_orientation_exif.json b/test/backend/assets/orientation/broken_orientation_exif.json similarity index 100% rename from test/backend/assets/broken_orientation_exif.json rename to test/backend/assets/orientation/broken_orientation_exif.json diff --git a/test/backend/assets/broken_orientation_exif2.jpg b/test/backend/assets/orientation/broken_orientation_exif2.jpg similarity index 100% rename from test/backend/assets/broken_orientation_exif2.jpg rename to test/backend/assets/orientation/broken_orientation_exif2.jpg diff --git a/test/backend/assets/broken_orientation_exif2.json b/test/backend/assets/orientation/broken_orientation_exif2.json similarity index 92% rename from test/backend/assets/broken_orientation_exif2.json rename to test/backend/assets/orientation/broken_orientation_exif2.json index d24b6edc..766c2002 100644 --- a/test/backend/assets/broken_orientation_exif2.json +++ b/test/backend/assets/orientation/broken_orientation_exif2.json @@ -9,7 +9,7 @@ }, "creationDate": 1185452882000, "fileSize": 124036, - "orientation": 8, + "orientation": 1, "size": { "height": 3072, "width": 2304 diff --git a/test/backend/unit/model/threading/DiskMangerWorker.spec.ts b/test/backend/unit/model/threading/DiskMangerWorker.spec.ts index 0a090480..e537d1b7 100644 --- a/test/backend/unit/model/threading/DiskMangerWorker.spec.ts +++ b/test/backend/unit/model/threading/DiskMangerWorker.spec.ts @@ -12,7 +12,7 @@ describe('DiskMangerWorker', () => { ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets'); const dir = await DiskMangerWorker.scanDirectory('/'); // should match the number of media (photo/video) files in the assets folder - expect(dir.media.length).to.be.equals(9); + expect(dir.media.length).to.be.equals(7); const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json')); const i = dir.media.findIndex(m => m.name === 'test image öüóőúéáű-.,.jpg'); expect(Utils.clone(dir.media[i].name)).to.be.deep.equal('test image öüóőúéáű-.,.jpg'); diff --git a/test/backend/unit/model/threading/MetaDataLoader.spec.ts b/test/backend/unit/model/threading/MetaDataLoader.spec.ts index 2082e7c4..a143074c 100644 --- a/test/backend/unit/model/threading/MetaDataLoader.spec.ts +++ b/test/backend/unit/model/threading/MetaDataLoader.spec.ts @@ -33,17 +33,38 @@ describe('MetadataLoader', () => { describe('should load jpg with proper height and orientation', () => { it('jpg 1', async () => { - const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/broken_orientation_exif.jpg')); - const expected = require(path.join(__dirname, '/../../../assets/broken_orientation_exif.json')); + const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif.jpg')); + const expected = require(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif.json')); expect(Utils.clone(data)).to.be.deep.equal(expected); }); it('jpg 2', async () => { - const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/broken_orientation_exif2.jpg')); - const expected = require(path.join(__dirname, '/../../../assets/broken_orientation_exif2.json')); + const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.jpg')); + const expected = require(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.json')); expect(Utils.clone(data)).to.be.deep.equal(expected); }); }); + describe('should read orientation', () => { + for (let i = 0; i <= 8; ++i) { + it('Landscape ' + i, async () => { + const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/Landscape_' + i + '.jpg')); + const expected = require(path.join(__dirname, '/../../../assets/orientation/Landscape.json')); + expected.orientation = i; + delete data.fileSize; + delete expected.fileSize; + expect(Utils.clone(data)).to.be.deep.equal(expected); + }); + it('Portrait ' + i, async () => { + const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/Portrait_' + i + '.jpg')); + const expected = require(path.join(__dirname, '/../../../assets/orientation/Portrait.json')); + expected.orientation = i; + delete data.fileSize; + delete expected.fileSize; + expect(Utils.clone(data)).to.be.deep.equal(expected); + }); + } + }); + it('should load jpg edited with exiftool', async () => { const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/exiftool.jpg'));