exifreader 3.14.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -26
- package/bin/build.js +12 -1
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +2 -0
- package/package.json +40 -25
- package/src/dom-parser.js +1 -1
- package/src/exif-reader.js +127 -18
- package/src/iptc-tags.js +34 -27
- package/src/tags.js +20 -20
- package/src/xmp-tags.js +17 -16
- package/webpack.config.js +17 -10
package/exif-reader.d.ts
CHANGED
|
@@ -263,6 +263,8 @@ interface Tags {
|
|
|
263
263
|
'DeviceSettingDescription'?: NumberTag & NumberArrayTag,
|
|
264
264
|
'SubjectDistanceRange'?: NumberTag,
|
|
265
265
|
'ImageUniqueID'?: StringArrayTag,
|
|
266
|
+
'LensMake'?: StringArrayTag,
|
|
267
|
+
'LensModel'?: StringArrayTag,
|
|
266
268
|
|
|
267
269
|
// GPS tags
|
|
268
270
|
'GPSVersionID'?: NumberTag,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -20,31 +20,34 @@
|
|
|
20
20
|
"exif-reader.d.ts",
|
|
21
21
|
"webpack.config.js"
|
|
22
22
|
],
|
|
23
|
-
"dependencies": {},
|
|
24
23
|
"types": "./exif-reader.d.ts",
|
|
24
|
+
"dependencies": {},
|
|
25
|
+
"optionalDependencies": {
|
|
26
|
+
"@xmldom/xmldom": "^0.7.5"
|
|
27
|
+
},
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"@babel/core": "^7.
|
|
27
|
-
"@babel/preset-env": "^7.
|
|
28
|
-
"@babel/register": "^7.
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"babel-loader": "^8.
|
|
29
|
+
"@babel/core": "^7.15.8",
|
|
30
|
+
"@babel/preset-env": "^7.15.8",
|
|
31
|
+
"@babel/register": "^7.15.3",
|
|
32
|
+
"@types/node": "^14.14.36",
|
|
33
|
+
"babel-loader": "^8.2.2",
|
|
31
34
|
"babel-plugin-rewire": "^1.2.0",
|
|
32
|
-
"chai": "^4.
|
|
33
|
-
"cross-env": "^
|
|
34
|
-
"cypress": "^
|
|
35
|
-
"cypress-file-upload": "^
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"eslint-plugin-cypress": "^2.
|
|
38
|
-
"husky": "^
|
|
39
|
-
"mocha": "^
|
|
35
|
+
"chai": "^4.3.4",
|
|
36
|
+
"cross-env": "^7.0.3",
|
|
37
|
+
"cypress": "^8.5.0",
|
|
38
|
+
"cypress-file-upload": "^5.0.8",
|
|
39
|
+
"eslint": "^8.0.0",
|
|
40
|
+
"eslint-plugin-cypress": "^2.12.1",
|
|
41
|
+
"husky": "^4.3.8",
|
|
42
|
+
"mocha": "^9.1.2",
|
|
40
43
|
"npm-run-all": "^4.1.5",
|
|
41
|
-
"nyc": "^
|
|
44
|
+
"nyc": "^15.1.0",
|
|
42
45
|
"rimraf": "^3.0.2",
|
|
43
|
-
"string-replace-loader": "^
|
|
44
|
-
"terser-webpack-plugin": "^2.
|
|
45
|
-
"webpack": "^
|
|
46
|
-
"webpack-cli": "^
|
|
47
|
-
"webpack-dev-server": "^3.
|
|
46
|
+
"string-replace-loader": "^3.0.3",
|
|
47
|
+
"terser-webpack-plugin": "^5.2.4",
|
|
48
|
+
"webpack": "^5.58.1",
|
|
49
|
+
"webpack-cli": "^4.9.0",
|
|
50
|
+
"webpack-dev-server": "^4.3.1"
|
|
48
51
|
},
|
|
49
52
|
"scripts": {
|
|
50
53
|
"build": "node bin/build.js",
|
|
@@ -52,8 +55,7 @@
|
|
|
52
55
|
"coverage": "nyc npm test",
|
|
53
56
|
"cypress:open": "cypress open",
|
|
54
57
|
"lint": "eslint .",
|
|
55
|
-
"
|
|
56
|
-
"start": "webpack-dev-server",
|
|
58
|
+
"start": "cross-env NODE_ENV=development webpack serve",
|
|
57
59
|
"test": "cross-env BABEL_ENV=test mocha --require @babel/register --recursive \"test/unit/\"",
|
|
58
60
|
"test:build": "mocha test/build/test.js",
|
|
59
61
|
"test:build:custom": "mocha --bail test/build/test-custom.js",
|
|
@@ -77,7 +79,20 @@
|
|
|
77
79
|
"**/node_modules/*"
|
|
78
80
|
]
|
|
79
81
|
},
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
+
"browserslist": [
|
|
83
|
+
"> 0.5%",
|
|
84
|
+
"last 2 versions",
|
|
85
|
+
"not dead",
|
|
86
|
+
"Chrome >= 9",
|
|
87
|
+
"Firefox >= 15",
|
|
88
|
+
"IE >= 10",
|
|
89
|
+
"Edge >= 12",
|
|
90
|
+
"Safari >= 5.1",
|
|
91
|
+
"Opera >= 12.1"
|
|
92
|
+
],
|
|
93
|
+
"husky": {
|
|
94
|
+
"hooks": {
|
|
95
|
+
"pre-commit": "npm-run-all lint test test:build"
|
|
96
|
+
}
|
|
82
97
|
}
|
|
83
98
|
}
|
package/src/dom-parser.js
CHANGED
|
@@ -11,7 +11,7 @@ function get() {
|
|
|
11
11
|
return DOMParser;
|
|
12
12
|
}
|
|
13
13
|
try {
|
|
14
|
-
return
|
|
14
|
+
return __non_webpack_require__('@xmldom/xmldom').DOMParser; // eslint-disable-line no-undef
|
|
15
15
|
} catch (error) {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
package/src/exif-reader.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ExifReader
|
|
3
3
|
* http://github.com/mattiasw/exifreader
|
|
4
|
-
* Copyright (C) 2011-
|
|
4
|
+
* Copyright (C) 2011-2021 Mattias Wallander <mattias@wallander.eu>
|
|
5
5
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
6
6
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
7
7
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
8
8
|
*/
|
|
9
|
+
/* global Buffer, __non_webpack_require__ */
|
|
9
10
|
|
|
10
11
|
import {objectAssign} from './utils.js';
|
|
11
12
|
import DataViewWrapper from './dataview.js';
|
|
@@ -30,7 +31,115 @@ export default {
|
|
|
30
31
|
|
|
31
32
|
export const errors = exifErrors;
|
|
32
33
|
|
|
33
|
-
export function load(data, options
|
|
34
|
+
export function load(data, options) {
|
|
35
|
+
if (isFilePathOrURL(data)) {
|
|
36
|
+
return loadFile(data).then((fileContents) => loadFromData(fileContents, options));
|
|
37
|
+
}
|
|
38
|
+
if (isBrowserFileObject(data)) {
|
|
39
|
+
return loadFileObject(data).then((fileContents) => loadFromData(fileContents, options));
|
|
40
|
+
}
|
|
41
|
+
return loadFromData(data, options);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isFilePathOrURL(data) {
|
|
45
|
+
return typeof data === 'string';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function loadFile(filename) {
|
|
49
|
+
if (typeof window !== 'undefined') {
|
|
50
|
+
return browserFetchRemoteFile(filename);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (/^https?:\/\//.test(filename)) {
|
|
54
|
+
return nodeFetchRemoteFile(filename).then((buffer) => {
|
|
55
|
+
return buffer;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return loadLocalFile(filename);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function browserFetchRemoteFile(url) {
|
|
63
|
+
return fetch(url).then((response) => response.arrayBuffer());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function nodeFetchRemoteFile(url) {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const get = requireNodeGet(url);
|
|
69
|
+
get(url, (response) => {
|
|
70
|
+
if ((response.statusCode >= 200) && (response.statusCode <= 299)) {
|
|
71
|
+
const data = [];
|
|
72
|
+
response.on('data', (chunk) => data.push(Buffer.from(chunk)));
|
|
73
|
+
response.on('error', (error) => reject(error));
|
|
74
|
+
response.on('end', () => resolve(Buffer.concat(data)));
|
|
75
|
+
} else {
|
|
76
|
+
reject(`Could not fetch file: ${response.statusCode} ${response.statusMessage}`);
|
|
77
|
+
response.resume();
|
|
78
|
+
}
|
|
79
|
+
}).on('error', (error) => reject(error));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function requireNodeGet(url) {
|
|
84
|
+
if (/^https:\/\//.test(url)) {
|
|
85
|
+
return __non_webpack_require__('https').get;
|
|
86
|
+
}
|
|
87
|
+
return __non_webpack_require__('http').get;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function loadLocalFile(filename) {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
const fs = requireNodeFs();
|
|
93
|
+
fs.open(filename, (error, fd) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
reject(error);
|
|
96
|
+
} else {
|
|
97
|
+
fs.stat(filename, (error, stat) => {
|
|
98
|
+
if (error) {
|
|
99
|
+
reject(error);
|
|
100
|
+
} else {
|
|
101
|
+
const buffer = Buffer.alloc(stat.size);
|
|
102
|
+
fs.read(fd, {buffer}, (error) => {
|
|
103
|
+
if (error) {
|
|
104
|
+
reject(error);
|
|
105
|
+
} else {
|
|
106
|
+
fs.close(fd, (error) => {
|
|
107
|
+
if (error) {
|
|
108
|
+
console.warn(`Could not close file ${filename}:`, error); // eslint-disable-line no-console
|
|
109
|
+
}
|
|
110
|
+
resolve(buffer);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function requireNodeFs() {
|
|
122
|
+
try {
|
|
123
|
+
return __non_webpack_require__('fs');
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isBrowserFileObject(data) {
|
|
130
|
+
return (typeof window !== 'undefined') && (typeof File !== 'undefined') && (data instanceof File);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function loadFileObject(file) {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
const reader = new FileReader();
|
|
136
|
+
reader.onload = (readerEvent) => resolve(readerEvent.target.result);
|
|
137
|
+
reader.onerror = () => reject(reader.error);
|
|
138
|
+
reader.readAsArrayBuffer(file);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function loadFromData(data, options) {
|
|
34
143
|
if (isNodeBuffer(data)) {
|
|
35
144
|
// File data read in Node can share the underlying buffer with other
|
|
36
145
|
// data. Therefore it's safest to get a new one to avoid weird bugs.
|
|
@@ -41,7 +150,7 @@ export function load(data, options = {expanded: false}) {
|
|
|
41
150
|
|
|
42
151
|
function isNodeBuffer(data) {
|
|
43
152
|
try {
|
|
44
|
-
return Buffer.isBuffer(data);
|
|
153
|
+
return Buffer.isBuffer(data);
|
|
45
154
|
} catch (error) {
|
|
46
155
|
return false;
|
|
47
156
|
}
|
|
@@ -55,7 +164,7 @@ function getDataView(data) {
|
|
|
55
164
|
}
|
|
56
165
|
}
|
|
57
166
|
|
|
58
|
-
export function loadView(dataView,
|
|
167
|
+
export function loadView(dataView, {expanded = false, includeUnknown = false} = {expanded: false, includeUnknown: false}) {
|
|
59
168
|
let foundMetaData = false;
|
|
60
169
|
let tags = {};
|
|
61
170
|
|
|
@@ -72,7 +181,7 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
72
181
|
if (Constants.USE_JPEG && Constants.USE_FILE && hasFileData(fileDataOffset)) {
|
|
73
182
|
foundMetaData = true;
|
|
74
183
|
const readTags = FileTags.read(dataView, fileDataOffset);
|
|
75
|
-
if (
|
|
184
|
+
if (expanded) {
|
|
76
185
|
tags.file = readTags;
|
|
77
186
|
} else {
|
|
78
187
|
tags = objectAssign({}, tags, readTags);
|
|
@@ -81,13 +190,13 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
81
190
|
|
|
82
191
|
if (Constants.USE_EXIF && hasExifData(tiffHeaderOffset)) {
|
|
83
192
|
foundMetaData = true;
|
|
84
|
-
const readTags = Tags.read(dataView, tiffHeaderOffset);
|
|
193
|
+
const readTags = Tags.read(dataView, tiffHeaderOffset, includeUnknown);
|
|
85
194
|
if (readTags.Thumbnail) {
|
|
86
195
|
tags.Thumbnail = readTags.Thumbnail;
|
|
87
196
|
delete readTags.Thumbnail;
|
|
88
197
|
}
|
|
89
198
|
|
|
90
|
-
if (
|
|
199
|
+
if (expanded) {
|
|
91
200
|
tags.exif = readTags;
|
|
92
201
|
addGpsGroup(tags);
|
|
93
202
|
} else {
|
|
@@ -95,8 +204,8 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
95
204
|
}
|
|
96
205
|
|
|
97
206
|
if (Constants.USE_TIFF && Constants.USE_IPTC && readTags['IPTC-NAA'] && !hasIptcData(iptcDataOffset)) {
|
|
98
|
-
const readIptcTags = IptcTags.read(readTags['IPTC-NAA'].value, 0);
|
|
99
|
-
if (
|
|
207
|
+
const readIptcTags = IptcTags.read(readTags['IPTC-NAA'].value, 0, includeUnknown);
|
|
208
|
+
if (expanded) {
|
|
100
209
|
tags.iptc = readIptcTags;
|
|
101
210
|
} else {
|
|
102
211
|
tags = objectAssign({}, tags, readIptcTags);
|
|
@@ -105,7 +214,7 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
105
214
|
|
|
106
215
|
if (Constants.USE_TIFF && Constants.USE_XMP && readTags['ApplicationNotes'] && !hasXmpData(xmpChunks)) {
|
|
107
216
|
const readXmpTags = XmpTags.read(getStringValueFromArray(readTags['ApplicationNotes'].value));
|
|
108
|
-
if (
|
|
217
|
+
if (expanded) {
|
|
109
218
|
tags.xmp = readXmpTags;
|
|
110
219
|
} else {
|
|
111
220
|
tags = objectAssign({}, tags, readXmpTags);
|
|
@@ -122,7 +231,7 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
122
231
|
chunksTotal: 1
|
|
123
232
|
}]
|
|
124
233
|
);
|
|
125
|
-
if (
|
|
234
|
+
if (expanded) {
|
|
126
235
|
tags.icc = readIccTags;
|
|
127
236
|
} else {
|
|
128
237
|
tags = objectAssign({}, tags, readIccTags);
|
|
@@ -132,8 +241,8 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
132
241
|
|
|
133
242
|
if (Constants.USE_JPEG && Constants.USE_IPTC && hasIptcData(iptcDataOffset)) {
|
|
134
243
|
foundMetaData = true;
|
|
135
|
-
const readTags = IptcTags.read(dataView, iptcDataOffset);
|
|
136
|
-
if (
|
|
244
|
+
const readTags = IptcTags.read(dataView, iptcDataOffset, includeUnknown);
|
|
245
|
+
if (expanded) {
|
|
137
246
|
tags.iptc = readTags;
|
|
138
247
|
} else {
|
|
139
248
|
tags = objectAssign({}, tags, readTags);
|
|
@@ -143,7 +252,7 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
143
252
|
if (Constants.USE_XMP && hasXmpData(xmpChunks)) {
|
|
144
253
|
foundMetaData = true;
|
|
145
254
|
const readTags = XmpTags.read(dataView, xmpChunks);
|
|
146
|
-
if (
|
|
255
|
+
if (expanded) {
|
|
147
256
|
tags.xmp = readTags;
|
|
148
257
|
} else {
|
|
149
258
|
tags = objectAssign({}, tags, readTags);
|
|
@@ -153,7 +262,7 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
153
262
|
if ((Constants.USE_JPEG || Constants.USE_WEBP) && Constants.USE_ICC && hasIccData(iccChunks)) {
|
|
154
263
|
foundMetaData = true;
|
|
155
264
|
const readTags = IccTags.read(dataView, iccChunks);
|
|
156
|
-
if (
|
|
265
|
+
if (expanded) {
|
|
157
266
|
tags.icc = readTags;
|
|
158
267
|
} else {
|
|
159
268
|
tags = objectAssign({}, tags, readTags);
|
|
@@ -162,8 +271,8 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
162
271
|
|
|
163
272
|
if (Constants.USE_MPF && hasMpfData(mpfDataOffset)) {
|
|
164
273
|
foundMetaData = true;
|
|
165
|
-
const readMpfTags = Tags.readMpf(dataView, mpfDataOffset);
|
|
166
|
-
if (
|
|
274
|
+
const readMpfTags = Tags.readMpf(dataView, mpfDataOffset, includeUnknown);
|
|
275
|
+
if (expanded) {
|
|
167
276
|
tags.mpf = readMpfTags;
|
|
168
277
|
} else {
|
|
169
278
|
tags = objectAssign({}, tags, readMpfTags);
|
|
@@ -173,7 +282,7 @@ export function loadView(dataView, options = {expanded: false}) {
|
|
|
173
282
|
if (Constants.USE_PNG && Constants.USE_PNG_FILE && hasPngFileData(pngHeaderOffset)) {
|
|
174
283
|
foundMetaData = true;
|
|
175
284
|
const readTags = PngFileTags.read(dataView, pngHeaderOffset);
|
|
176
|
-
if (
|
|
285
|
+
if (expanded) {
|
|
177
286
|
tags.pngFile = readTags;
|
|
178
287
|
} else {
|
|
179
288
|
tags = objectAssign({}, tags, readTags);
|
package/src/iptc-tags.js
CHANGED
|
@@ -15,13 +15,13 @@ export default {
|
|
|
15
15
|
read
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
function read(dataView, dataOffset) {
|
|
18
|
+
function read(dataView, dataOffset, includeUnknown) {
|
|
19
19
|
try {
|
|
20
20
|
if (Array.isArray(dataView)) {
|
|
21
|
-
return parseTags(new DataView(Uint8Array.from(dataView).buffer), {size: dataView.length}, 0);
|
|
21
|
+
return parseTags(new DataView(Uint8Array.from(dataView).buffer), {size: dataView.length}, 0, includeUnknown);
|
|
22
22
|
}
|
|
23
23
|
const {naaBlock, dataOffset: newDataOffset} = getNaaResourceBlock(dataView, dataOffset);
|
|
24
|
-
return parseTags(dataView, naaBlock, newDataOffset);
|
|
24
|
+
return parseTags(dataView, naaBlock, newDataOffset, includeUnknown);
|
|
25
25
|
} catch (error) {
|
|
26
26
|
return {};
|
|
27
27
|
}
|
|
@@ -62,42 +62,44 @@ function getBlockPadding(resourceBlock) {
|
|
|
62
62
|
return 0;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function parseTags(dataView, naaBlock, dataOffset) {
|
|
65
|
+
function parseTags(dataView, naaBlock, dataOffset, includeUnknown) {
|
|
66
66
|
const tags = {};
|
|
67
67
|
let encoding = undefined;
|
|
68
68
|
|
|
69
69
|
const endOfBlockOffset = dataOffset + naaBlock['size'];
|
|
70
70
|
|
|
71
71
|
while ((dataOffset < endOfBlockOffset) && (dataOffset < dataView.byteLength)) {
|
|
72
|
-
const {tag, tagSize} = readTag(dataView, dataOffset, tags, encoding);
|
|
72
|
+
const {tag, tagSize} = readTag(dataView, dataOffset, tags, encoding, includeUnknown);
|
|
73
73
|
|
|
74
74
|
if (tag === null) {
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
if (
|
|
79
|
-
encoding
|
|
80
|
-
|
|
78
|
+
if (tag) {
|
|
79
|
+
if ('encoding' in tag) {
|
|
80
|
+
encoding = tag.encoding;
|
|
81
|
+
}
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
if ((tags[tag.name] === undefined) || (tag['repeatable'] === undefined)) {
|
|
84
|
+
tags[tag.name] = {
|
|
85
|
+
id: tag.id,
|
|
86
|
+
value: tag.value,
|
|
87
|
+
description: tag.description
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
if (!(tags[tag.name] instanceof Array)) {
|
|
91
|
+
tags[tag.name] = [{
|
|
92
|
+
id: tags[tag.name].id,
|
|
93
|
+
value: tags[tag.name].value,
|
|
94
|
+
description: tags[tag.name].description
|
|
95
|
+
}];
|
|
96
|
+
}
|
|
97
|
+
tags[tag.name].push({
|
|
98
|
+
id: tag.id,
|
|
99
|
+
value: tag.value,
|
|
100
|
+
description: tag.description
|
|
101
|
+
});
|
|
95
102
|
}
|
|
96
|
-
tags[tag.name].push({
|
|
97
|
-
id: tag.id,
|
|
98
|
-
value: tag.value,
|
|
99
|
-
description: tag.description
|
|
100
|
-
});
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
dataOffset += TAG_HEADER_SIZE + tagSize;
|
|
@@ -106,7 +108,7 @@ function parseTags(dataView, naaBlock, dataOffset) {
|
|
|
106
108
|
return tags;
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
function readTag(dataView, dataOffset, tags, encoding) {
|
|
111
|
+
function readTag(dataView, dataOffset, tags, encoding, includeUnknown) {
|
|
110
112
|
const TAG_CODE_OFFSET = 1;
|
|
111
113
|
const TAG_SIZE_OFFSET = 3;
|
|
112
114
|
|
|
@@ -116,6 +118,11 @@ function readTag(dataView, dataOffset, tags, encoding) {
|
|
|
116
118
|
|
|
117
119
|
const tagCode = dataView.getUint16(dataOffset + TAG_CODE_OFFSET);
|
|
118
120
|
const tagSize = dataView.getUint16(dataOffset + TAG_SIZE_OFFSET);
|
|
121
|
+
|
|
122
|
+
if (!includeUnknown && !IptcTagNames['iptc'][tagCode]) {
|
|
123
|
+
return {tag: undefined, tagSize};
|
|
124
|
+
}
|
|
125
|
+
|
|
119
126
|
const tagValue = getTagValue(dataView, dataOffset + TAG_HEADER_SIZE, tagSize);
|
|
120
127
|
|
|
121
128
|
const tag = {
|
package/src/tags.js
CHANGED
|
@@ -30,51 +30,51 @@ export default {
|
|
|
30
30
|
readMpf
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
function read(dataView, tiffHeaderOffset) {
|
|
33
|
+
function read(dataView, tiffHeaderOffset, includeUnknown) {
|
|
34
34
|
const byteOrder = ByteOrder.getByteOrder(dataView, tiffHeaderOffset);
|
|
35
|
-
let tags = read0thIfd(dataView, tiffHeaderOffset, byteOrder);
|
|
36
|
-
tags = readExifIfd(tags, dataView, tiffHeaderOffset, byteOrder);
|
|
37
|
-
tags = readGpsIfd(tags, dataView, tiffHeaderOffset, byteOrder);
|
|
38
|
-
tags = readInteroperabilityIfd(tags, dataView, tiffHeaderOffset, byteOrder);
|
|
35
|
+
let tags = read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown);
|
|
36
|
+
tags = readExifIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown);
|
|
37
|
+
tags = readGpsIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown);
|
|
38
|
+
tags = readInteroperabilityIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown);
|
|
39
39
|
|
|
40
40
|
return tags;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function read0thIfd(dataView, tiffHeaderOffset, byteOrder) {
|
|
44
|
-
return readIfd(dataView, '0th', tiffHeaderOffset, get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder), byteOrder);
|
|
43
|
+
function read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown) {
|
|
44
|
+
return readIfd(dataView, '0th', tiffHeaderOffset, get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder), byteOrder, includeUnknown);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder) {
|
|
48
48
|
return tiffHeaderOffset + Types.getLongAt(dataView, tiffHeaderOffset + 4, byteOrder);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function readExifIfd(tags, dataView, tiffHeaderOffset, byteOrder) {
|
|
51
|
+
function readExifIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown) {
|
|
52
52
|
if (tags[EXIF_IFD_POINTER_KEY] !== undefined) {
|
|
53
|
-
return objectAssign(tags, readIfd(dataView, 'exif', tiffHeaderOffset, tiffHeaderOffset + tags[EXIF_IFD_POINTER_KEY].value, byteOrder));
|
|
53
|
+
return objectAssign(tags, readIfd(dataView, 'exif', tiffHeaderOffset, tiffHeaderOffset + tags[EXIF_IFD_POINTER_KEY].value, byteOrder, includeUnknown));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return tags;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function readGpsIfd(tags, dataView, tiffHeaderOffset, byteOrder) {
|
|
59
|
+
function readGpsIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown) {
|
|
60
60
|
if (tags[GPS_INFO_IFD_POINTER_KEY] !== undefined) {
|
|
61
|
-
return objectAssign(tags, readIfd(dataView, 'gps', tiffHeaderOffset, tiffHeaderOffset + tags[GPS_INFO_IFD_POINTER_KEY].value, byteOrder));
|
|
61
|
+
return objectAssign(tags, readIfd(dataView, 'gps', tiffHeaderOffset, tiffHeaderOffset + tags[GPS_INFO_IFD_POINTER_KEY].value, byteOrder, includeUnknown));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
return tags;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function readInteroperabilityIfd(tags, dataView, tiffHeaderOffset, byteOrder) {
|
|
67
|
+
function readInteroperabilityIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown) {
|
|
68
68
|
if (tags[INTEROPERABILITY_IFD_POINTER_KEY] !== undefined) {
|
|
69
|
-
return objectAssign(tags, readIfd(dataView, 'interoperability', tiffHeaderOffset, tiffHeaderOffset + tags[INTEROPERABILITY_IFD_POINTER_KEY].value, byteOrder));
|
|
69
|
+
return objectAssign(tags, readIfd(dataView, 'interoperability', tiffHeaderOffset, tiffHeaderOffset + tags[INTEROPERABILITY_IFD_POINTER_KEY].value, byteOrder, includeUnknown));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
return tags;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
function readMpf(dataView, dataOffset) {
|
|
75
|
+
function readMpf(dataView, dataOffset, includeUnknown) {
|
|
76
76
|
const byteOrder = ByteOrder.getByteOrder(dataView, dataOffset);
|
|
77
|
-
const tags = readIfd(dataView, 'mpf', dataOffset, get0thIfdOffset(dataView, dataOffset, byteOrder), byteOrder);
|
|
77
|
+
const tags = readIfd(dataView, 'mpf', dataOffset, get0thIfdOffset(dataView, dataOffset, byteOrder), byteOrder, includeUnknown);
|
|
78
78
|
return addMpfImages(dataView, dataOffset, tags, byteOrder);
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -202,7 +202,7 @@ function isFirstIndividualImage(i) {
|
|
|
202
202
|
return i === 0;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
function readIfd(dataView, ifdType, tiffHeaderOffset, offset, byteOrder) {
|
|
205
|
+
function readIfd(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, includeUnknown) {
|
|
206
206
|
const FIELD_COUNT_SIZE = Types.getTypeSize('SHORT');
|
|
207
207
|
const FIELD_SIZE = 12;
|
|
208
208
|
|
|
@@ -215,7 +215,7 @@ function readIfd(dataView, ifdType, tiffHeaderOffset, offset, byteOrder) {
|
|
|
215
215
|
break;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
const tag = readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder);
|
|
218
|
+
const tag = readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, includeUnknown);
|
|
219
219
|
if (tag !== undefined) {
|
|
220
220
|
tags[tag.name] = {
|
|
221
221
|
'id': tag.id,
|
|
@@ -230,7 +230,7 @@ function readIfd(dataView, ifdType, tiffHeaderOffset, offset, byteOrder) {
|
|
|
230
230
|
if (Constants.USE_THUMBNAIL && (offset < dataView.byteLength - Types.getTypeSize('LONG'))) {
|
|
231
231
|
const nextIfdOffset = Types.getLongAt(dataView, offset, byteOrder);
|
|
232
232
|
if (nextIfdOffset !== 0) {
|
|
233
|
-
tags['Thumbnail'] = readIfd(dataView, ifdType, tiffHeaderOffset, tiffHeaderOffset + nextIfdOffset, byteOrder);
|
|
233
|
+
tags['Thumbnail'] = readIfd(dataView, ifdType, tiffHeaderOffset, tiffHeaderOffset + nextIfdOffset, byteOrder, true);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
|
|
@@ -244,7 +244,7 @@ function getNumberOfFields(dataView, offset, byteOrder) {
|
|
|
244
244
|
return 0;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
function readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder) {
|
|
247
|
+
function readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, includeUnknown) {
|
|
248
248
|
const TAG_CODE_IPTC_NAA = 0x83bb;
|
|
249
249
|
const TAG_TYPE_OFFSET = Types.getTypeSize('SHORT');
|
|
250
250
|
const TAG_COUNT_OFFSET = TAG_TYPE_OFFSET + Types.getTypeSize('SHORT');
|
|
@@ -255,7 +255,7 @@ function readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder) {
|
|
|
255
255
|
const tagCount = Types.getLongAt(dataView, offset + TAG_COUNT_OFFSET, byteOrder);
|
|
256
256
|
let tagValue;
|
|
257
257
|
|
|
258
|
-
if (Types.typeSizes[tagType] === undefined) {
|
|
258
|
+
if (Types.typeSizes[tagType] === undefined || (!includeUnknown && TagNames[ifdType][tagCode] === undefined)) {
|
|
259
259
|
return undefined;
|
|
260
260
|
}
|
|
261
261
|
|
package/src/xmp-tags.js
CHANGED
|
@@ -217,6 +217,9 @@ function isNamespaceDefinition(name) {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
function getLocalName(name) {
|
|
220
|
+
if (/^MicrosoftPhoto(_\d+_)?:Rating$/i.test(name)) {
|
|
221
|
+
return 'RatingPercent';
|
|
222
|
+
}
|
|
220
223
|
return name.split(':')[1];
|
|
221
224
|
}
|
|
222
225
|
|
|
@@ -251,7 +254,7 @@ function getDescriptionOfObject(value) {
|
|
|
251
254
|
const descriptions = [];
|
|
252
255
|
|
|
253
256
|
for (const key in value) {
|
|
254
|
-
descriptions.push(`${getClearTextKey(key)}: ${value[key].value}`);
|
|
257
|
+
descriptions.push(`${getClearTextKey(key)}: ${getDescription(value[key].value)}`);
|
|
255
258
|
}
|
|
256
259
|
|
|
257
260
|
return descriptions.join('; ');
|
|
@@ -300,11 +303,14 @@ function parseNodeChildrenAsTags(children) {
|
|
|
300
303
|
function parseNodeAsTag(node, name) {
|
|
301
304
|
if (hasNestedSimpleRdfDescription(node)) {
|
|
302
305
|
return parseNodeAsSimpleRdfDescription(node, name);
|
|
303
|
-
}
|
|
306
|
+
}
|
|
307
|
+
if (hasNestedStructureRdfDescription(node)) {
|
|
304
308
|
return parseNodeAsStructureRdfDescription(node, name);
|
|
305
|
-
}
|
|
309
|
+
}
|
|
310
|
+
if (isCompactStructure(node)) {
|
|
306
311
|
return parseNodeAsCompactStructure(node, name);
|
|
307
|
-
}
|
|
312
|
+
}
|
|
313
|
+
if (isArray(node)) {
|
|
308
314
|
return parseNodeAsArray(node, name);
|
|
309
315
|
}
|
|
310
316
|
return parseNodeAsSimpleValue(node, name);
|
|
@@ -387,6 +393,7 @@ function parseNodeAsStructureRdfDescription(node, name) {
|
|
|
387
393
|
|
|
388
394
|
function isCompactStructure(node) {
|
|
389
395
|
return (Object.keys(node.value).length === 0)
|
|
396
|
+
&& (node.attributes['xml:lang'] === undefined)
|
|
390
397
|
&& (node.attributes['rdf:resource'] === undefined);
|
|
391
398
|
}
|
|
392
399
|
|
|
@@ -434,20 +441,14 @@ function parseArrayValue(item) {
|
|
|
434
441
|
if (hasNestedSimpleRdfDescription(item)) {
|
|
435
442
|
return parseNodeAsSimpleRdfDescription(item);
|
|
436
443
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
444
|
+
if (hasNestedStructureRdfDescription(item)) {
|
|
445
|
+
return parseNodeAsStructureRdfDescription(item).value;
|
|
446
|
+
}
|
|
447
|
+
if (isCompactStructure(item)) {
|
|
448
|
+
return parseNodeAsCompactStructure(item).value;
|
|
440
449
|
}
|
|
441
450
|
|
|
442
|
-
return
|
|
443
|
-
value: item.value,
|
|
444
|
-
attributes: parseNodeAttributes(item),
|
|
445
|
-
description: getDescription(item.value)
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
function hasNestedArrayValue(node) {
|
|
450
|
-
return node.attributes['rdf:parseType'] === 'Resource';
|
|
451
|
+
return parseNodeAsSimpleValue(item);
|
|
451
452
|
}
|
|
452
453
|
|
|
453
454
|
function parseNodeAsSimpleValue(node, name) {
|