diff --git a/package-lock.json b/package-lock.json index 96be8c81..9e43eca4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", @@ -12233,8 +12233,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" }, @@ -12242,7 +12243,7 @@ "image-size": "bin/image-size.js" }, "engines": { - "node": ">=14.0.0" + "node": ">=16.x" } }, "node_modules/immutable": { @@ -29977,7 +29978,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" } diff --git a/package.json b/package.json index 70e71323..08c10923 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index 0e08ef5e..a7f474da 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -205,6 +205,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 (isNaN(metadata.size.width) || metadata.size.width == null) { + metadata.size.width = 0; + } + if (isNaN(metadata.size.height) || metadata.size.height == null) { + metadata.size.height = 0; + } } @@ -297,10 +304,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 diff --git a/test/backend/assets/parsingfromheic.heic b/test/backend/assets/parsingfromheic.heic new file mode 100644 index 00000000..c2cee1fa Binary files /dev/null and b/test/backend/assets/parsingfromheic.heic differ diff --git a/test/backend/assets/parsingfromheic.json b/test/backend/assets/parsingfromheic.json new file mode 100644 index 00000000..df8f2a6b --- /dev/null +++ b/test/backend/assets/parsingfromheic.json @@ -0,0 +1,15 @@ +{ + "positionData": { + "GPSData": { + "latitude": 9.061331, + "longitude": 38.761711 + } + }, + "creationDate": 1706438594000, + "creationDateOffset": "+03:00", + "fileSize": 2158564, + "size": { + "height": 512, + "width": 512 + } +} \ No newline at end of file diff --git a/test/backend/unit/model/threading/MetaDataLoader.spec.ts b/test/backend/unit/model/threading/MetaDataLoader.spec.ts index 76365e88..c47f4975 100644 --- a/test/backend/unit/model/threading/MetaDataLoader.spec.ts +++ b/test/backend/unit/model/threading/MetaDataLoader.spec.ts @@ -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'));