1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-10 11:10:35 +02:00

Fixing Orientation reading issue and adding orientation reading tests #212

This commit is contained in:
Patrik J. Braun 2021-03-28 13:24:55 +02:00
parent 5020949a88
commit 36ecbcbd3d
27 changed files with 56 additions and 18 deletions

View File

@ -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) {

View File

@ -0,0 +1,9 @@
{
"creationDate": 1566424388000,
"fileSize": 349915,
"orientation": 1,
"size": {
"height": 1200,
"width": 1800
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

View File

@ -0,0 +1,9 @@
{
"creationDate": 1566424388000,
"fileSize": 349915,
"orientation": 1,
"size": {
"height": 1800,
"width": 1200
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

View File

Before

Width:  |  Height:  |  Size: 250 KiB

After

Width:  |  Height:  |  Size: 250 KiB

View File

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 121 KiB

View File

@ -9,7 +9,7 @@
},
"creationDate": 1185452882000,
"fileSize": 124036,
"orientation": 8,
"orientation": 1,
"size": {
"height": 3072,
"width": 2304

View File

@ -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');

View File

@ -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'));