@eris/exif
Advanced tools
Comparing version 0.4.2-alpha.18 to 0.4.2-alpha.19
@@ -27,2 +27,3 @@ /// <reference types="node" /> | ||
private _readLargestJPEG; | ||
private _mergeIFDMetadata; | ||
extractJPEG(options?: IJPEGOptions): IBufferLike; | ||
@@ -29,0 +30,0 @@ extractMetadata(): IGenericMetadata; |
@@ -244,2 +244,22 @@ "use strict"; | ||
} | ||
_mergeIFDMetadata(entries) { | ||
const tags = {}; | ||
// Merge the tags from all the IFD entries: | ||
// - trust data from embedded JPEGs least | ||
// - trust data from EXIF tables next | ||
// - pull size data from full resolution subifds | ||
const nonExifEntries = entries.filter(entry => !entry.ifd.isEXIF); | ||
const exifEntries = entries.filter(entry => entry.ifd.isEXIF); | ||
const fullResolutionEntries = entries.filter(entry => entry.metadata.NewSubfileType === 0); | ||
for (const { metadata } of nonExifEntries.concat(exifEntries)) { | ||
Object.assign(tags, metadata); | ||
} | ||
for (const { metadata } of fullResolutionEntries) { | ||
const { ImageWidth, ImageLength } = metadata; | ||
if (!ImageWidth || !ImageLength) | ||
continue; | ||
Object.assign(tags, { ImageWidth, ImageLength }); | ||
} | ||
return tags; | ||
} | ||
extractJPEG(options = {}) { | ||
@@ -262,6 +282,5 @@ if (this._cachedJPEG) | ||
this._readIFDs(); | ||
const exifTags = {}; | ||
const tags = {}; | ||
const entries = []; | ||
this._ifds.forEach(ifd => { | ||
const target = ifd.isEXIF ? exifTags : tags; | ||
const tagsForIfd = {}; | ||
ifd.entries.forEach(entry => { | ||
@@ -276,10 +295,11 @@ const name = tags_1.getFriendlyName(entry.tag); | ||
return; | ||
target[name] = value; | ||
tagsForIfd[name] = value; | ||
const panasonicName = tags_1.panasonicConversionTags[name]; | ||
if (this._variant === Variant.Panasonic && panasonicName) { | ||
target[panasonicName] = value; | ||
tagsForIfd[panasonicName] = value; | ||
} | ||
entries.push({ ifd, metadata: tagsForIfd }); | ||
}); | ||
}); | ||
this._cachedMetadata = Object.assign({}, tags, exifTags); | ||
this._cachedMetadata = this._mergeIFDMetadata(entries); | ||
return Object.assign({}, this._cachedMetadata); | ||
@@ -286,0 +306,0 @@ } |
@@ -14,3 +14,6 @@ "use strict"; | ||
yResolution: ['YResolution'], | ||
createdAt: [['DateTimeOriginal', date_parser_1.parseDate], ['CreateDate', date_parser_1.parseDate]], | ||
createdAt: [ | ||
['DateTimeOriginal', date_parser_1.parseDate], | ||
['CreateDate', date_parser_1.parseDate], | ||
], | ||
modifiedAt: [['ModifyDate', date_parser_1.parseDate]], | ||
@@ -17,0 +20,0 @@ iso: ['ISO'], |
@@ -284,2 +284,27 @@ import {IFD} from '../decoder/ifd' | ||
private _mergeIFDMetadata( | ||
entries: Array<{ifd: IIFD; metadata: IGenericMetadata}>, | ||
): IGenericMetadata { | ||
const tags: IGenericMetadata = {} | ||
// Merge the tags from all the IFD entries: | ||
// - trust data from embedded JPEGs least | ||
// - trust data from EXIF tables next | ||
// - pull size data from full resolution subifds | ||
const nonExifEntries = entries.filter(entry => !entry.ifd.isEXIF) | ||
const exifEntries = entries.filter(entry => entry.ifd.isEXIF) | ||
const fullResolutionEntries = entries.filter(entry => entry.metadata.NewSubfileType === 0) | ||
for (const {metadata} of nonExifEntries.concat(exifEntries)) { | ||
Object.assign(tags, metadata) | ||
} | ||
for (const {metadata} of fullResolutionEntries) { | ||
const {ImageWidth, ImageLength} = metadata | ||
if (!ImageWidth || !ImageLength) continue | ||
Object.assign(tags, {ImageWidth, ImageLength}) | ||
} | ||
return tags | ||
} | ||
public extractJPEG(options: IJPEGOptions = {}): IBufferLike { | ||
@@ -305,6 +330,6 @@ if (this._cachedJPEG) return this._cachedJPEG.slice() | ||
const exifTags: IGenericMetadata = {} | ||
const tags: IGenericMetadata = {} | ||
const entries: Array<{ifd: IIFD; metadata: IGenericMetadata}> = [] | ||
this._ifds.forEach(ifd => { | ||
const target = ifd.isEXIF ? exifTags : tags | ||
const tagsForIfd: IGenericMetadata = {} | ||
ifd.entries.forEach(entry => { | ||
@@ -319,12 +344,14 @@ const name = getFriendlyName(entry.tag) | ||
if (typeof value !== 'string' && typeof value !== 'number') return | ||
target[name] = value | ||
tagsForIfd[name] = value | ||
const panasonicName = panasonicConversionTags[name] | ||
if (this._variant === Variant.Panasonic && panasonicName) { | ||
target[panasonicName] = value | ||
tagsForIfd[panasonicName] = value | ||
} | ||
entries.push({ifd, metadata: tagsForIfd}) | ||
}) | ||
}) | ||
this._cachedMetadata = {...tags, ...exifTags} | ||
this._cachedMetadata = this._mergeIFDMetadata(entries) | ||
return {...this._cachedMetadata} | ||
@@ -331,0 +358,0 @@ } |
@@ -26,3 +26,6 @@ import {parseDate} from './date-parser' | ||
createdAt: [['DateTimeOriginal', parseDate], ['CreateDate', parseDate]], | ||
createdAt: [ | ||
['DateTimeOriginal', parseDate], | ||
['CreateDate', parseDate], | ||
], | ||
modifiedAt: [['ModifyDate', parseDate]], | ||
@@ -29,0 +32,0 @@ |
{ | ||
"name": "@eris/exif", | ||
"version": "0.4.2-alpha.18", | ||
"version": "0.4.2-alpha.19", | ||
"description": "Parses EXIF data.", | ||
@@ -41,3 +41,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "f648c51e5d6c7eb10146f3db679c4cd6eccbc9c8" | ||
"gitHead": "7b7e6677c8003d01ca492c3292e16c1735e31f03" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
280265
5096