Fixing Orientation reading issue and adding orientation reading tests #212
@ -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 = <any>parseInt(exif.Rating.value, 10);
|
||||
}
|
||||
|
||||
if (exif.Orientation) {
|
||||
metadata.orientation = <any>parseInt(<any>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) {
|
||||
|
9
test/backend/assets/orientation/Landscape.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"creationDate": 1566424388000,
|
||||
"fileSize": 349915,
|
||||
"orientation": 1,
|
||||
"size": {
|
||||
"height": 1200,
|
||||
"width": 1800
|
||||
}
|
||||
}
|
BIN
test/backend/assets/orientation/Landscape_0.jpg
Normal file
After Width: | Height: | Size: 342 KiB |
BIN
test/backend/assets/orientation/Landscape_1.jpg
Normal file
After Width: | Height: | Size: 339 KiB |
BIN
test/backend/assets/orientation/Landscape_2.jpg
Normal file
After Width: | Height: | Size: 341 KiB |
BIN
test/backend/assets/orientation/Landscape_3.jpg
Normal file
After Width: | Height: | Size: 341 KiB |
BIN
test/backend/assets/orientation/Landscape_4.jpg
Normal file
After Width: | Height: | Size: 340 KiB |
BIN
test/backend/assets/orientation/Landscape_5.jpg
Normal file
After Width: | Height: | Size: 343 KiB |
BIN
test/backend/assets/orientation/Landscape_6.jpg
Normal file
After Width: | Height: | Size: 344 KiB |
BIN
test/backend/assets/orientation/Landscape_7.jpg
Normal file
After Width: | Height: | Size: 344 KiB |
BIN
test/backend/assets/orientation/Landscape_8.jpg
Normal file
After Width: | Height: | Size: 344 KiB |
9
test/backend/assets/orientation/Portrait.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"creationDate": 1566424388000,
|
||||
"fileSize": 349915,
|
||||
"orientation": 1,
|
||||
"size": {
|
||||
"height": 1800,
|
||||
"width": 1200
|
||||
}
|
||||
}
|
BIN
test/backend/assets/orientation/Portrait_0.jpg
Normal file
After Width: | Height: | Size: 243 KiB |
BIN
test/backend/assets/orientation/Portrait_1.jpg
Normal file
After Width: | Height: | Size: 240 KiB |
BIN
test/backend/assets/orientation/Portrait_2.jpg
Normal file
After Width: | Height: | Size: 241 KiB |
BIN
test/backend/assets/orientation/Portrait_3.jpg
Normal file
After Width: | Height: | Size: 242 KiB |
BIN
test/backend/assets/orientation/Portrait_4.jpg
Normal file
After Width: | Height: | Size: 241 KiB |
BIN
test/backend/assets/orientation/Portrait_5.jpg
Normal file
After Width: | Height: | Size: 246 KiB |
BIN
test/backend/assets/orientation/Portrait_6.jpg
Normal file
After Width: | Height: | Size: 246 KiB |
BIN
test/backend/assets/orientation/Portrait_7.jpg
Normal file
After Width: | Height: | Size: 245 KiB |
BIN
test/backend/assets/orientation/Portrait_8.jpg
Normal file
After Width: | Height: | Size: 246 KiB |
Before Width: | Height: | Size: 250 KiB After Width: | Height: | Size: 250 KiB |
Before Width: | Height: | Size: 121 KiB After Width: | Height: | Size: 121 KiB |
@ -9,7 +9,7 @@
|
||||
},
|
||||
"creationDate": 1185452882000,
|
||||
"fileSize": 124036,
|
||||
"orientation": 8,
|
||||
"orientation": 1,
|
||||
"size": {
|
||||
"height": 3072,
|
||||
"width": 2304
|
@ -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');
|
||||
|
@ -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'));
|
||||
|