exifreader 4.5.0 → 4.6.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/exif-reader.d.ts CHANGED
@@ -131,7 +131,7 @@ interface ExpandedTags {
131
131
  pngFile?: PngFileTags,
132
132
  exif?: Tags,
133
133
  iptc?: Tags,
134
- xmp?: XmpTags,
134
+ xmp?: { _raw: string } & XmpTags,
135
135
  icc?: IccTags,
136
136
  Thumbnail?: ThumbnailTags,
137
137
  gps?: GpsTags
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -21,7 +21,6 @@
21
21
  "webpack.config.js"
22
22
  ],
23
23
  "types": "./exif-reader.d.ts",
24
- "dependencies": {},
25
24
  "optionalDependencies": {
26
25
  "@xmldom/xmldom": "^0.7.5"
27
26
  },
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ExifReader
3
3
  * http://github.com/mattiasw/exifreader
4
- * Copyright (C) 2011-2021 Mattias Wallander <mattias@wallander.eu>
4
+ * Copyright (C) 2011-2022 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/.
@@ -93,15 +93,11 @@ export default {
93
93
  0x0119: 'MaxSampleValue',
94
94
  0x011a: {
95
95
  'name': 'XResolution',
96
- 'description': (value) => {
97
- return '' + Math.round(value[0] / value[1]);
98
- }
96
+ 'description': TagNamesCommon.XResolution
99
97
  },
100
98
  0x011b: {
101
99
  'name': 'YResolution',
102
- 'description': (value) => {
103
- return '' + Math.round(value[0] / value[1]);
104
- }
100
+ 'description': TagNamesCommon.YResolution
105
101
  },
106
102
  0x011c: 'PlanarConfiguration',
107
103
  0x011d: 'PageName',
@@ -129,15 +125,7 @@ export default {
129
125
  },
130
126
  0x0128: {
131
127
  name: 'ResolutionUnit',
132
- description: (value) => {
133
- if (value === 2) {
134
- return 'inches';
135
- }
136
- if (value === 3) {
137
- return 'centimeters';
138
- }
139
- return 'Unknown';
140
- }
128
+ description: TagNamesCommon.ResolutionUnit
141
129
  },
142
130
  0x0129: 'PageNumber',
143
131
  0x012d: 'TransferFunction',
@@ -3,7 +3,104 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  export default {
6
- 'LightSource': (value) => {
6
+ ApertureValue: (value) => Math.pow(Math.sqrt(2), value[0] / value[1]).toFixed(2),
7
+ ColorSpace(value) {
8
+ if (value === 1) {
9
+ return 'sRGB';
10
+ } else if (value === 0xffff) {
11
+ return 'Uncalibrated';
12
+ }
13
+ return 'Unknown';
14
+ },
15
+ ComponentsConfiguration(value) {
16
+ return value.map((character) => {
17
+ if (character === 0x31) {
18
+ return 'Y';
19
+ } else if (character === 0x32) {
20
+ return 'Cb';
21
+ } else if (character === 0x33) {
22
+ return 'Cr';
23
+ } else if (character === 0x34) {
24
+ return 'R';
25
+ } else if (character === 0x35) {
26
+ return 'G';
27
+ } else if (character === 0x36) {
28
+ return 'B';
29
+ }
30
+ }).join('');
31
+ },
32
+ Contrast(value) {
33
+ if (value === 0) {
34
+ return 'Normal';
35
+ } else if (value === 1) {
36
+ return 'Soft';
37
+ } else if (value === 2) {
38
+ return 'Hard';
39
+ }
40
+ return 'Unknown';
41
+ },
42
+ CustomRendered(value) {
43
+ if (value === 0) {
44
+ return 'Normal process';
45
+ } else if (value === 1) {
46
+ return 'Custom process';
47
+ }
48
+ return 'Unknown';
49
+ },
50
+ ExposureMode(value) {
51
+ if (value === 0) {
52
+ return 'Auto exposure';
53
+ } else if (value === 1) {
54
+ return 'Manual exposure';
55
+ } else if (value === 2) {
56
+ return 'Auto bracket';
57
+ }
58
+ return 'Unknown';
59
+ },
60
+ ExposureProgram(value) {
61
+ if (value === 0) {
62
+ return 'Undefined';
63
+ } else if (value === 1) {
64
+ return 'Manual';
65
+ } else if (value === 2) {
66
+ return 'Normal program';
67
+ } else if (value === 3) {
68
+ return 'Aperture priority';
69
+ } else if (value === 4) {
70
+ return 'Shutter priority';
71
+ } else if (value === 5) {
72
+ return 'Creative program';
73
+ } else if (value === 6) {
74
+ return 'Action program';
75
+ } else if (value === 7) {
76
+ return 'Portrait mode';
77
+ } else if (value === 8) {
78
+ return 'Landscape mode';
79
+ } else if (value === 9) {
80
+ return 'Bulb';
81
+ }
82
+ return 'Unknown';
83
+ },
84
+ ExposureTime(value) {
85
+ if (value[0] >= value[1]) {
86
+ return `${Math.round(value[0] / value[1])}`;
87
+ }
88
+ if (value[0] !== 0) {
89
+ return `1/${Math.round(value[1] / value[0])}`;
90
+ }
91
+ return `0/${value[1]}`;
92
+ },
93
+ FNumber: (value) => `f/${value[0] / value[1]}`,
94
+ FocalLength: (value) => (value[0] / value[1]) + ' mm',
95
+ FocalPlaneResolutionUnit(value) {
96
+ if (value === 2) {
97
+ return 'inches';
98
+ } else if (value === 3) {
99
+ return 'centimeters';
100
+ }
101
+ return 'Unknown';
102
+ },
103
+ LightSource: (value) => {
7
104
  if (value === 1) {
8
105
  return 'Daylight';
9
106
  } else if (value === 2) {
@@ -46,5 +143,81 @@ export default {
46
143
  return 'Other light source';
47
144
  }
48
145
  return 'Unknown';
49
- }
146
+ },
147
+ MeteringMode(value) {
148
+ if (value === 1) {
149
+ return 'Average';
150
+ } else if (value === 2) {
151
+ return 'CenterWeightedAverage';
152
+ } else if (value === 3) {
153
+ return 'Spot';
154
+ } else if (value === 4) {
155
+ return 'MultiSpot';
156
+ } else if (value === 5) {
157
+ return 'Pattern';
158
+ } else if (value === 6) {
159
+ return 'Partial';
160
+ } else if (value === 255) {
161
+ return 'Other';
162
+ }
163
+ return 'Unknown';
164
+ },
165
+ ResolutionUnit(value) {
166
+ if (value === 2) {
167
+ return 'inches';
168
+ }
169
+ if (value === 3) {
170
+ return 'centimeters';
171
+ }
172
+ return 'Unknown';
173
+ },
174
+ Saturation(value) {
175
+ if (value === 0) {
176
+ return 'Normal';
177
+ } else if (value === 1) {
178
+ return 'Low saturation';
179
+ } else if (value === 2) {
180
+ return 'High saturation';
181
+ }
182
+ return 'Unknown';
183
+ },
184
+ SceneCaptureType(value) {
185
+ if (value === 0) {
186
+ return 'Standard';
187
+ } else if (value === 1) {
188
+ return 'Landscape';
189
+ } else if (value === 2) {
190
+ return 'Portrait';
191
+ } else if (value === 3) {
192
+ return 'Night scene';
193
+ }
194
+ return 'Unknown';
195
+ },
196
+ Sharpness(value) {
197
+ if (value === 0) {
198
+ return 'Normal';
199
+ } else if (value === 1) {
200
+ return 'Soft';
201
+ } else if (value === 2) {
202
+ return 'Hard';
203
+ }
204
+ return 'Unknown';
205
+ },
206
+ ShutterSpeedValue(value) {
207
+ const denominator = Math.pow(2, value[0] / value[1]);
208
+ if (denominator <= 1) {
209
+ return `${Math.round(1 / denominator)}`;
210
+ }
211
+ return `1/${Math.round(denominator)}`;
212
+ },
213
+ WhiteBalance(value) {
214
+ if (value === 0) {
215
+ return 'Auto white balance';
216
+ } else if (value === 1) {
217
+ return 'Manual white balance';
218
+ }
219
+ return 'Unknown';
220
+ },
221
+ XResolution: (value) => '' + Math.round(value[0] / value[1]),
222
+ YResolution: (value) => '' + Math.round(value[0] / value[1])
50
223
  };
@@ -8,43 +8,15 @@ import TagNamesCommon from './tag-names-common.js';
8
8
  export default {
9
9
  0x829a: {
10
10
  'name': 'ExposureTime',
11
- 'description': (value) => {
12
- if (value[0] !== 0) {
13
- return `1/${Math.round(value[1] / value[0])}`;
14
- }
15
- return `0/${value[1]}`;
16
- }
11
+ 'description': TagNamesCommon.ExposureTime
17
12
  },
18
13
  0x829d: {
19
14
  'name': 'FNumber',
20
- 'description': (value) => `f/${value[0] / value[1]}`
15
+ 'description': TagNamesCommon.FNumber
21
16
  },
22
17
  0x8822: {
23
18
  'name': 'ExposureProgram',
24
- 'description': (value) => {
25
- if (value === 0) {
26
- return 'Undefined';
27
- } else if (value === 1) {
28
- return 'Manual';
29
- } else if (value === 2) {
30
- return 'Normal program';
31
- } else if (value === 3) {
32
- return 'Aperture priority';
33
- } else if (value === 4) {
34
- return 'Shutter priority';
35
- } else if (value === 5) {
36
- return 'Creative program';
37
- } else if (value === 6) {
38
- return 'Action program';
39
- } else if (value === 7) {
40
- return 'Portrait mode';
41
- } else if (value === 8) {
42
- return 'Landscape mode';
43
- } else if (value === 9) {
44
- return 'Bulb';
45
- }
46
- return 'Unknown';
47
- }
19
+ 'description': TagNamesCommon.ExposureProgram
48
20
  },
49
21
  0x8824: 'SpectralSensitivity',
50
22
  0x8827: 'ISOSpeedRatings',
@@ -83,36 +55,16 @@ export default {
83
55
  0x9012: 'OffsetTimeDigitized',
84
56
  0x9101: {
85
57
  'name': 'ComponentsConfiguration',
86
- 'description': (value) => {
87
- return value.map((character) => {
88
- if (character === 0x31) {
89
- return 'Y';
90
- } else if (character === 0x32) {
91
- return 'Cb';
92
- } else if (character === 0x33) {
93
- return 'Cr';
94
- } else if (character === 0x34) {
95
- return 'R';
96
- } else if (character === 0x35) {
97
- return 'G';
98
- } else if (character === 0x36) {
99
- return 'B';
100
- }
101
- }).join('');
102
- }
58
+ 'description': TagNamesCommon.ComponentsConfiguration
103
59
  },
104
60
  0x9102: 'CompressedBitsPerPixel',
105
61
  0x9201: {
106
62
  'name': 'ShutterSpeedValue',
107
- 'description': (value) => {
108
- return `1/${Math.round(Math.pow(2, value[0] / value[1]))}`;
109
- }
63
+ 'description': TagNamesCommon.ShutterSpeedValue
110
64
  },
111
65
  0x9202: {
112
66
  'name': 'ApertureValue',
113
- 'description': (value) => {
114
- return Math.pow(Math.sqrt(2), value[0] / value[1]).toFixed(2);
115
- }
67
+ 'description': TagNamesCommon.ApertureValue
116
68
  },
117
69
  0x9203: 'BrightnessValue',
118
70
  0x9204: 'ExposureBiasValue',
@@ -128,28 +80,11 @@ export default {
128
80
  },
129
81
  0x9207: {
130
82
  'name': 'MeteringMode',
131
- 'description': (value) => {
132
- if (value === 1) {
133
- return 'Average';
134
- } else if (value === 2) {
135
- return 'CenterWeightedAverage';
136
- } else if (value === 3) {
137
- return 'Spot';
138
- } else if (value === 4) {
139
- return 'MultiSpot';
140
- } else if (value === 5) {
141
- return 'Pattern';
142
- } else if (value === 6) {
143
- return 'Partial';
144
- } else if (value === 255) {
145
- return 'Other';
146
- }
147
- return 'Unknown';
148
- }
83
+ 'description': TagNamesCommon.MeteringMode
149
84
  },
150
85
  0x9208: {
151
86
  'name': 'LightSource',
152
- description: TagNamesCommon['LightSource']
87
+ description: TagNamesCommon.LightSource
153
88
  },
154
89
  0x9209: {
155
90
  'name': 'Flash',
@@ -204,7 +139,7 @@ export default {
204
139
  },
205
140
  0x920a: {
206
141
  'name': 'FocalLength',
207
- 'description': (value) => (value[0] / value[1]) + ' mm'
142
+ 'description': TagNamesCommon.FocalLength
208
143
  },
209
144
  0x9211: 'ImageNumber',
210
145
  0x9212: {
@@ -272,14 +207,7 @@ export default {
272
207
  },
273
208
  0xa001: {
274
209
  'name': 'ColorSpace',
275
- 'description': (value) => {
276
- if (value === 1) {
277
- return 'sRGB';
278
- } else if (value === 0xffff) {
279
- return 'Uncalibrated';
280
- }
281
- return 'Unknown';
282
- }
210
+ 'description': TagNamesCommon.ColorSpace
283
211
  },
284
212
  0xa002: 'PixelXDimension',
285
213
  0xa003: 'PixelYDimension',
@@ -294,14 +222,7 @@ export default {
294
222
  0xa20f: 'FocalPlaneYResolution',
295
223
  0xa210: {
296
224
  'name': 'FocalPlaneResolutionUnit',
297
- 'description': (value) => {
298
- if (value === 2) {
299
- return 'inches';
300
- } else if (value === 3) {
301
- return 'centimeters';
302
- }
303
- return 'Unknown';
304
- }
225
+ 'description': TagNamesCommon.FocalPlaneResolutionUnit
305
226
  },
306
227
  0xa214: {
307
228
  'name': 'SubjectLocation',
@@ -353,38 +274,15 @@ export default {
353
274
  },
354
275
  0xa401: {
355
276
  'name': 'CustomRendered',
356
- 'description': (value) => {
357
- if (value === 0) {
358
- return 'Normal process';
359
- } else if (value === 1) {
360
- return 'Custom process';
361
- }
362
- return 'Unknown';
363
- }
277
+ 'description': TagNamesCommon.CustomRendered
364
278
  },
365
279
  0xa402: {
366
280
  'name': 'ExposureMode',
367
- 'description': (value) => {
368
- if (value === 0) {
369
- return 'Auto exposure';
370
- } else if (value === 1) {
371
- return 'Manual exposure';
372
- } else if (value === 2) {
373
- return 'Auto bracket';
374
- }
375
- return 'Unknown';
376
- }
281
+ 'description': TagNamesCommon.ExposureMode
377
282
  },
378
283
  0xa403: {
379
284
  'name': 'WhiteBalance',
380
- 'description': (value) => {
381
- if (value === 0) {
382
- return 'Auto white balance';
383
- } else if (value === 1) {
384
- return 'Manual white balance';
385
- }
386
- return 'Unknown';
387
- }
285
+ 'description': TagNamesCommon.WhiteBalance
388
286
  },
389
287
  0xa404: {
390
288
  'name': 'DigitalZoomRatio',
@@ -406,18 +304,7 @@ export default {
406
304
  },
407
305
  0xa406: {
408
306
  'name': 'SceneCaptureType',
409
- 'description': (value) => {
410
- if (value === 0) {
411
- return 'Standard';
412
- } else if (value === 1) {
413
- return 'Landscape';
414
- } else if (value === 2) {
415
- return 'Portrait';
416
- } else if (value === 3) {
417
- return 'Night scene';
418
- }
419
- return 'Unknown';
420
- }
307
+ 'description': TagNamesCommon.SceneCaptureType
421
308
  },
422
309
  0xa407: {
423
310
  'name': 'GainControl',
@@ -438,42 +325,15 @@ export default {
438
325
  },
439
326
  0xa408: {
440
327
  'name': 'Contrast',
441
- 'description': (value) => {
442
- if (value === 0) {
443
- return 'Normal';
444
- } else if (value === 1) {
445
- return 'Soft';
446
- } else if (value === 2) {
447
- return 'Hard';
448
- }
449
- return 'Unknown';
450
- }
328
+ 'description': TagNamesCommon.Contrast
451
329
  },
452
330
  0xa409: {
453
331
  'name': 'Saturation',
454
- 'description': (value) => {
455
- if (value === 0) {
456
- return 'Normal';
457
- } else if (value === 1) {
458
- return 'Low saturation';
459
- } else if (value === 2) {
460
- return 'High saturation';
461
- }
462
- return 'Unknown';
463
- }
332
+ 'description': TagNamesCommon.Saturation
464
333
  },
465
334
  0xa40a: {
466
335
  'name': 'Sharpness',
467
- 'description': (value) => {
468
- if (value === 0) {
469
- return 'Normal';
470
- } else if (value === 1) {
471
- return 'Soft';
472
- } else if (value === 2) {
473
- return 'Hard';
474
- }
475
- return 'Unknown';
476
- }
336
+ 'description': TagNamesCommon.Sharpness
477
337
  },
478
338
  0xa40b: {
479
339
  'name': 'DeviceSettingDescription',
@@ -2,6 +2,8 @@
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
+ import TagNamesCommon from './tag-names-common.js';
6
+
5
7
  export default {
6
8
  'tiff:Orientation'(value) {
7
9
  if (value === '1') {
@@ -30,10 +32,59 @@ export default {
30
32
  }
31
33
  return value;
32
34
  },
35
+ 'tiff:ResolutionUnit': (value) => TagNamesCommon.ResolutionUnit(parseInt(value, 10)),
36
+ 'tiff:XResolution': (value) => fraction(TagNamesCommon.XResolution, value),
37
+ 'tiff:YResolution': (value) => fraction(TagNamesCommon.YResolution, value),
38
+ 'exif:ApertureValue': (value) => fraction(TagNamesCommon.ApertureValue, value),
33
39
  'exif:GPSLatitude': calculateGPSValue,
34
- 'exif:GPSLongitude': calculateGPSValue
40
+ 'exif:GPSLongitude': calculateGPSValue,
41
+ 'exif:FNumber': (value) => fraction(TagNamesCommon.FNumber, value),
42
+ 'exif:FocalLength': (value) => fraction(TagNamesCommon.FocalLength, value),
43
+ 'exif:FocalPlaneResolutionUnit': (value) => TagNamesCommon.FocalPlaneResolutionUnit(parseInt(value, 10)),
44
+ 'exif:ColorSpace': (value) => TagNamesCommon.ColorSpace(parseNumber(value)),
45
+ 'exif:ComponentsConfiguration'(value, description) {
46
+ if (/^\d, \d, \d, \d$/.test(description)) {
47
+ const numbers = description.split(', ').map((number) => number.charCodeAt(0));
48
+ return TagNamesCommon.ComponentsConfiguration(numbers);
49
+ }
50
+ return description;
51
+ },
52
+ 'exif:Contrast': (value) => TagNamesCommon.Contrast(parseInt(value, 10)),
53
+ 'exif:CustomRendered': (value) => TagNamesCommon.CustomRendered(parseInt(value, 10)),
54
+ 'exif:ExposureMode': (value) => TagNamesCommon.ExposureMode(parseInt(value, 10)),
55
+ 'exif:ExposureProgram': (value) => TagNamesCommon.ExposureProgram(parseInt(value, 10)),
56
+ 'exif:ExposureTime'(value) {
57
+ if (isFraction(value)) {
58
+ return TagNamesCommon.ExposureTime(value.split('/').map((number) => parseInt(number, 10)));
59
+ }
60
+ return value;
61
+ },
62
+ 'exif:MeteringMode': (value) => TagNamesCommon.MeteringMode(parseInt(value, 10)),
63
+ 'exif:Saturation': (value) => TagNamesCommon.Saturation(parseInt(value, 10)),
64
+ 'exif:SceneCaptureType': (value) => TagNamesCommon.SceneCaptureType(parseInt(value, 10)),
65
+ 'exif:Sharpness': (value) => TagNamesCommon.Sharpness(parseInt(value, 10)),
66
+ 'exif:ShutterSpeedValue': (value) => fraction(TagNamesCommon.ShutterSpeedValue, value),
67
+ 'exif:WhiteBalance': (value) => TagNamesCommon.WhiteBalance(parseInt(value, 10))
35
68
  };
36
69
 
70
+ function fraction(func, value) {
71
+ if (isFraction(value)) {
72
+ return func(value.split('/'));
73
+ }
74
+ return value;
75
+ }
76
+
77
+ function parseNumber(value) {
78
+ if (value.substring(0, 2) === '0x') {
79
+ return parseInt(value.substring(2), 16);
80
+ }
81
+ return parseInt(value, 10);
82
+ }
83
+
84
+ function isFraction(value) {
85
+ return /^-?\d+\/-?\d+$/.test(value);
86
+ }
87
+
37
88
  function calculateGPSValue(value) {
38
89
  const [degreesString, minutesString] = value.split(',');
39
90
  if ((degreesString !== undefined) && (minutesString !== undefined)) {
package/src/xmp-tags.js CHANGED
@@ -229,7 +229,11 @@ function getLocalName(name) {
229
229
 
230
230
  function getDescription(value, name = undefined) {
231
231
  if (Array.isArray(value)) {
232
- return getDescriptionOfArray(value);
232
+ const arrayDescription = getDescriptionOfArray(value);
233
+ if ((name) && (typeof XmpTagNames[name] === 'function')) {
234
+ return XmpTagNames[name](value, arrayDescription);
235
+ }
236
+ return arrayDescription;
233
237
  }
234
238
  if (typeof value === 'object') {
235
239
  return getDescriptionOfObject(value);