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

Unit test and bugfix for CreationDate (#8)

This commit is contained in:
grasdk 2024-03-07 09:29:44 +01:00 committed by GitHub
parent 3811fc3c99
commit 2af6115f2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 23 deletions

View File

@ -362,34 +362,27 @@ export class MetadataLoader {
//Filesystem is the absolute last resort, and it's hard to write tests for, since file system dates are changed on e.g. git clone. //Filesystem is the absolute last resort, and it's hard to write tests for, since file system dates are changed on e.g. git clone.
if (exif.exif.DateTimeOriginal) { if (exif.exif.DateTimeOriginal) {
//DateTimeOriginal is when the camera shutter closed //DateTimeOriginal is when the camera shutter closed
if (exif.exif.OffsetTimeOriginal) { //OffsetTimeOriginal is the corresponding offset let offset = exif.exif.OffsetTimeOriginal; //OffsetTimeOriginal is the corresponding offset
metadata.creationDate = timestampToMS(exif.exif.DateTimeOriginal, exif.exif.OffsetTimeOriginal); if (!offset) { //Find offset among other options if possible
metadata.creationDateOffset = exif.exif.OffsetTimeOriginal; offset = exif.exif.OffsetTimeDigitized || exif.exif.OffsetTime || getTimeOffsetByGPSStamp(exif.exif.DateTimeOriginal, exif.exif.GPSTimeStamp, exif.gps);
} else {
const alt_offset = exif.exif.OffsetTimeDigitized || exif.exif.OffsetTime || getTimeOffsetByGPSStamp(exif.exif.DateTimeOriginal, exif.exif.GPSTimeStamp, exif.gps);
metadata.creationDate = timestampToMS(exif.exif.DateTimeOriginal, alt_offset);
metadata.creationDateOffset = alt_offset;
} }
metadata.creationDate = timestampToMS(exif.exif.DateTimeOriginal, offset);
metadata.creationDateOffset = offset;
} else if (exif.exif.CreateDate) { //using else if here, because DateTimeOriginal has preceedence } else if (exif.exif.CreateDate) { //using else if here, because DateTimeOriginal has preceedence
//Create is when the camera wrote the file (typically within the same ms as shutter close) //Create is when the camera wrote the file (typically within the same ms as shutter close)
if (exif.exif.OffsetTimeDigitized) { //OffsetTimeDigitized is the corresponding offset let offset = exif.exif.OffsetTimeDigitized; //OffsetTimeDigitized is the corresponding offset
metadata.creationDate = timestampToMS(exif.exif.CreateDate, exif.exif.OffsetTimeDigitized); if (!offset) { //Find offset among other options if possible
metadata.creationDateOffset = exif.exif.OffsetTimeDigitized; offset = exif.exif.OffsetTimeOriginal || exif.exif.OffsetTime || getTimeOffsetByGPSStamp(exif.exif.DateTimeOriginal, exif.exif.GPSTimeStamp, exif.gps);
} else {
const alt_offset = exif.exif.OffsetTimeOriginal || exif.exif.OffsetTime || getTimeOffsetByGPSStamp(exif.exif.DateTimeOriginal, exif.exif.GPSTimeStamp, exif.gps);
metadata.creationDate = timestampToMS(exif.exif.DateTimeOriginal, alt_offset);
metadata.creationDateOffset = alt_offset;
} }
metadata.creationDate = timestampToMS(exif.exif.CreateDate, offset);
metadata.creationDateOffset = offset;
} else if (exif.ifd0?.ModifyDate) { //using else if here, because DateTimeOriginal and CreatDate have preceedence } else if (exif.ifd0?.ModifyDate) { //using else if here, because DateTimeOriginal and CreatDate have preceedence
if (exif.exif.OffsetTime) { let offset = exif.exif.OffsetTime; //exif.Offsettime is the offset corresponding to ifd0.ModifyDate
//exif.Offsettime is the offset corresponding to ifd0.ModifyDate if (!offset) { //Find offset among other options if possible
metadata.creationDate = timestampToMS(exif.ifd0.ModifyDate, exif.exif?.OffsetTime); offset = exif.exif.DateTimeOriginal || exif.exif.OffsetTimeDigitized || getTimeOffsetByGPSStamp(exif.ifd0.ModifyDate, exif.exif.GPSTimeStamp, exif.gps);
metadata.creationDateOffset = exif.exif?.OffsetTime
} else {
const alt_offset = exif.exif.DateTimeOriginal || exif.exif.OffsetTimeDigitized || getTimeOffsetByGPSStamp(exif.ifd0.ModifyDate, exif.exif.GPSTimeStamp, exif.gps);
metadata.creationDate = timestampToMS(exif.ifd0.ModifyDate, alt_offset);
metadata.creationDateOffset = alt_offset;
} }
metadata.creationDate = timestampToMS(exif.ifd0.ModifyDate, offset);
metadata.creationDateOffset = offset
} else if (exif.ihdr && exif.ihdr["Creation Time"]) {// again else if (another fallback date if the good ones aren't there) { } else if (exif.ihdr && exif.ihdr["Creation Time"]) {// again else if (another fallback date if the good ones aren't there) {
const any_offset = exif.exif.DateTimeOriginal || exif.exif.OffsetTimeDigitized || exif.exif.OffsetTime || getTimeOffsetByGPSStamp(exif.ifd0.ModifyDate, exif.exif.GPSTimeStamp, exif.gps); const any_offset = exif.exif.DateTimeOriginal || exif.exif.OffsetTimeDigitized || exif.exif.OffsetTime || getTimeOffsetByGPSStamp(exif.ifd0.ModifyDate, exif.exif.GPSTimeStamp, exif.gps);
metadata.creationDate = timestampToMS(exif.ihdr["Creation Time"], any_offset); metadata.creationDate = timestampToMS(exif.ihdr["Creation Time"], any_offset);

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -0,0 +1,20 @@
{
"size": {
"width": 306,
"height": 204
},
"creationDate": 1435910683000,
"fileSize": 59564,
"positionData": {
"country": "United States",
"state": "Arizona",
"city": "Williams"
},
"keywords": ["Akela the wolf", "Balu the bear", "Bearizona", "Hugin the raven", "USA", "USA Road trip"],
"cameraData": {
"make": "Canon",
"model": "Canon EOS 600D",
"lens": "EF-S15-85mm f/3.5-5.6 IS USM"
},
"creationDateOffset": "+02:00"
}

View File

@ -112,6 +112,11 @@ describe('MetadataLoader', () => {
expect(Utils.clone(data)).to.be.deep.equal(expected); expect(Utils.clone(data)).to.be.deep.equal(expected);
}); });
}); });
it('should load wild-1-small image with CreateDate from 2015, but no DateTimeOriginal', async () => {
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/wild-1-small.jpg'));
const expected = require(path.join(__dirname, '/../../../assets/wild-1-small.json'));
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
describe('should load jpg with edge case exif data', () => { describe('should load jpg with edge case exif data', () => {
const root = path.join(__dirname, '/../../../assets/edge_case_exif_data'); const root = path.join(__dirname, '/../../../assets/edge_case_exif_data');