1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Adding support for metadataLoader to read ImageWidth and ImageHeight exif tags #516

This commit is contained in:
Patrik J. Braun 2023-03-05 15:45:01 +01:00
parent 47507a5d67
commit 9f2cd38019
4 changed files with 31 additions and 1 deletions

View File

@ -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};

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@ -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
}
}

View File

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