diff --git a/src/model/metadata.js b/src/model/metadata.js index 9532dbc..ae22a80 100644 --- a/src/model/metadata.js +++ b/src/model/metadata.js @@ -30,6 +30,9 @@ class Metadata { this.animated = animated(exiftool) this.rating = rating(exiftool) this.favourite = favourite(picasa) + const size = dimensions(exiftool) + this.width = size.width + this.height = size.height this.exif = opts ? (opts.embedExif ? exiftool.EXIF : undefined) : undefined // metadata could also include fields like // - lat = 51.5 @@ -127,4 +130,21 @@ function makeArray (value) { return Array.isArray(value) ? value : [value] } +function dimensions (exif) { + // Use the Composite field to avoid having to check all possible tag groups (EXIF, QuickTime, ASF...) + if (!exif.Composite) { + return { + width: null, + height: null + } + } else { + const size = exif.Composite.ImageSize + const x = size.indexOf('x') + return { + width: parseInt(size.substr(0, x), 10), + height: parseInt(size.substr(x + 1), 10) + } + } +} + module.exports = Metadata diff --git a/test/model/metadata.spec.js b/test/model/metadata.spec.js index 1a7e58d..7ffdbd3 100644 --- a/test/model/metadata.spec.js +++ b/test/model/metadata.spec.js @@ -218,4 +218,21 @@ describe('Metadata', function () { should(meta.favourite).eql(true) }) }) + + describe('size', function () { + it('can get an image width and height', function () { + const exiftool = fixtures.exiftool() + exiftool.Composite = { ImageSize: '800x600' } + const meta = new Metadata(exiftool) + should(meta.width).eql(800) + should(meta.height).eql(600) + }) + + it('defaults to null otherwise', function () { + const exiftool = fixtures.exiftool() + const meta = new Metadata(exiftool) + should(meta.width).eql(null) + should(meta.width).eql(null) + }) + }) })