1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-25 02:04:15 +02:00

updated image-size to read dimensions from heic file

This commit is contained in:
gras 2024-04-06 00:31:11 +02:00
parent 89caba6536
commit d52d7c0c4d
7 changed files with 39 additions and 8 deletions

13
package-lock.json generated
View File

@ -20,7 +20,7 @@
"express": "4.18.2",
"express-unless": "2.1.3",
"fluent-ffmpeg": "2.1.2",
"image-size": "1.0.2",
"image-size": "1.1.1",
"locale": "0.1.0",
"node-geocoder": "4.2.0",
"nodemailer": "6.9.4",
@ -12234,8 +12234,9 @@
}
},
"node_modules/image-size": {
"version": "1.0.2",
"license": "MIT",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-1.1.1.tgz",
"integrity": "sha512-541xKlUw6jr/6gGuk92F+mYM5zaFAc5ahphvkqvNe2bQ6gVBkd6bfrmVJ2t4KDAfikAYZyIqTnktX3i6/aQDrQ==",
"dependencies": {
"queue": "6.0.2"
},
@ -12243,7 +12244,7 @@
"image-size": "bin/image-size.js"
},
"engines": {
"node": ">=14.0.0"
"node": ">=16.x"
}
},
"node_modules/immutable": {
@ -29978,7 +29979,9 @@
}
},
"image-size": {
"version": "1.0.2",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-1.1.1.tgz",
"integrity": "sha512-541xKlUw6jr/6gGuk92F+mYM5zaFAc5ahphvkqvNe2bQ6gVBkd6bfrmVJ2t4KDAfikAYZyIqTnktX3i6/aQDrQ==",
"requires": {
"queue": "6.0.2"
}

View File

@ -47,7 +47,7 @@
"express": "4.18.2",
"express-unless": "2.1.3",
"fluent-ffmpeg": "2.1.2",
"image-size": "1.0.2",
"image-size": "1.1.1",
"locale": "0.1.0",
"node-geocoder": "4.2.0",
"nodemailer": "6.9.4",

View File

@ -206,6 +206,13 @@ export class MetadataLoader {
} catch (e) {
//in case of failure, set dimensions to 0 so they may be read via tags
metadata.size = { width: 0, height: 0 };
} finally {
if (metadata.size.width == undefined || metadata.size.width == null) {
metadata.size.width = 0;
}
if (metadata.size.height == undefined || metadata.size.height == null) {
metadata.size.height = 0;
}
}
@ -338,10 +345,10 @@ export class MetadataLoader {
private static mapImageDimensions(metadata: PhotoMetadata, exif: any, orientation: number) {
if (metadata.size.width <= 0) {
metadata.size.width = exif.ifd0?.ImageWidth || exif.exif?.ExifImageWidth;
metadata.size.width = exif.ifd0?.ImageWidth || exif.exif?.ExifImageWidth || metadata.size.width;
}
if (metadata.size.height <= 0) {
metadata.size.height = exif.ifd0?.ImageHeight || exif.exif?.ExifImageHeight;
metadata.size.height = exif.ifd0?.ImageHeight || exif.exif?.ExifImageHeight || metadata.size.height;
}
metadata.size.height = Math.max(metadata.size.height, 1); //ensure height dimension is positive
metadata.size.width = Math.max(metadata.size.width, 1); //ensure width dimension is positive

Binary file not shown.

View File

@ -0,0 +1,15 @@
{
"positionData": {
"GPSData": {
"latitude": 9.061331,
"longitude": 38.761711
}
},
"creationDate": 1706438594000,
"creationDateOffset": "+03:00",
"fileSize": 2158564,
"size": {
"height": 512,
"width": 512
}
}

View File

@ -23,6 +23,12 @@ describe('MetadataLoader', () => {
});
it('should load heic', async () => {
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/parsingfromheic.heic'));
const expected = require(path.join(__dirname, '/../../../assets/parsingfromheic.json'));
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
it('should load png', async () => {
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/test_png.png'));
const expected = require(path.join(__dirname, '/../../../assets/test_png.json'));

Binary file not shown.