Skip to content

Commit

Permalink
Merge pull request #879 from grasdk/bug/heic-dimensions
Browse files Browse the repository at this point in the history
updated image-size dependency to read dimensions from heic file
  • Loading branch information
bpatrik authored Apr 11, 2024
2 parents 2e6bff1 + 333678f commit 8c86dcb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions src/backend/model/fileaccess/MetadataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down Expand Up @@ -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
Expand Down
Binary file added test/backend/assets/parsingfromheic.heic
Binary file not shown.
15 changes: 15 additions & 0 deletions test/backend/assets/parsingfromheic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"positionData": {
"GPSData": {
"latitude": 9.061331,
"longitude": 38.761711
}
},
"creationDate": 1706438594000,
"creationDateOffset": "+03:00",
"fileSize": 2158564,
"size": {
"height": 512,
"width": 512
}
}
6 changes: 6 additions & 0 deletions test/backend/unit/model/threading/MetaDataLoader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 8c86dcb

Please sign in to comment.