exifreader 4.24.0 → 4.26.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 +34 -28
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +9 -1
- package/package.json +3 -3
- package/src/canon-tags.js +61 -0
- package/src/constants.js +2 -1
- package/src/exif-reader.js +22 -1
- package/src/png-text-tags.js +2 -2
- package/src/tag-names-0th-ifd.js +29 -5
- package/src/tag-names-canon-ifd.js +10 -0
- package/src/tag-names.js +3 -0
- package/src/tags-helpers.js +9 -3
- package/src/tags.js +1 -1
- package/webpack.config.js +6 -1
package/exif-reader.d.ts
CHANGED
|
@@ -207,6 +207,7 @@ export interface ExpandedTags {
|
|
|
207
207
|
Thumbnail?: ThumbnailTags,
|
|
208
208
|
gps?: GpsTags
|
|
209
209
|
photoshop?: PhotoshopTags;
|
|
210
|
+
makerNotes?: CanonTags;
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
interface GpsTags {
|
|
@@ -256,6 +257,13 @@ interface PhotoshopTags {
|
|
|
256
257
|
ClippingPathName: StringTag;
|
|
257
258
|
}
|
|
258
259
|
|
|
260
|
+
interface CanonTags {
|
|
261
|
+
AutoRotate: {
|
|
262
|
+
value: number,
|
|
263
|
+
description: 'None' | 'Rotate 90 CW' | 'Rotate 180' | 'Rotate 270 CW' | 'Unknown'
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
259
267
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer): Tags;
|
|
260
268
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded: true, includeUnknown?: boolean, length?: number, async?: false}): ExpandedTags;
|
|
261
269
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded?: false, includeUnknown?: boolean, length?: number, async?: false}): Tags;
|
|
@@ -517,7 +525,7 @@ interface IccTags {
|
|
|
517
525
|
[name: string]: ValueTag;
|
|
518
526
|
}
|
|
519
527
|
|
|
520
|
-
export type Tags = XmpTags & IccTags & PngTags & RiffTags & GifTags & PhotoshopTags & {
|
|
528
|
+
export type Tags = XmpTags & IccTags & PngTags & RiffTags & GifTags & PhotoshopTags & CanonTags & {
|
|
521
529
|
'Thumbnail'?: ThumbnailTags;
|
|
522
530
|
'Images'?: MPFImageTags[],
|
|
523
531
|
} & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.26.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"eslint": "^8.52.0",
|
|
38
38
|
"eslint-plugin-cypress": "^3.0.2",
|
|
39
39
|
"husky": "^9.0.11",
|
|
40
|
-
"mocha": "^
|
|
40
|
+
"mocha": "^11.0.1",
|
|
41
41
|
"npm-run-all": "^4.1.5",
|
|
42
42
|
"nyc": "^17.0.0",
|
|
43
43
|
"rimraf": "^5.0.5",
|
|
44
44
|
"string-replace-loader": "^3.1.0",
|
|
45
45
|
"terser-webpack-plugin": "^5.3.10",
|
|
46
46
|
"typescript": "^5.6.2",
|
|
47
|
-
"webpack": "
|
|
47
|
+
"webpack": "5.97.1",
|
|
48
48
|
"webpack-cli": "^5.1.4",
|
|
49
49
|
"webpack-dev-server": "^5.0.4"
|
|
50
50
|
},
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
// Reverse-engineered docs:
|
|
6
|
+
// https://exiftool.org/makernote_types.html
|
|
7
|
+
// https://exiv2.org/makernote.html
|
|
8
|
+
// https://exiv2.org/tags-canon.html
|
|
9
|
+
// https://gist.github.com/redaktor/bae0ef2377ab70bc5276
|
|
10
|
+
// https://www.ozhiker.com/electronics/pjmt/jpeg_info/canon_mn.html
|
|
11
|
+
|
|
12
|
+
import {objectAssign} from './utils.js';
|
|
13
|
+
import {readIfd} from './tags-helpers.js';
|
|
14
|
+
import {IFD_TYPE_CANON} from './tag-names.js';
|
|
15
|
+
|
|
16
|
+
const SHOT_INFO_AUTO_ROTATE = 27; // First position is size.
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
read,
|
|
20
|
+
SHOT_INFO_AUTO_ROTATE
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function read(dataView, tiffHeaderOffset, offset, byteOrder, includeUnknown) {
|
|
24
|
+
let tags = readIfd(dataView, IFD_TYPE_CANON, tiffHeaderOffset, tiffHeaderOffset + offset, byteOrder, includeUnknown);
|
|
25
|
+
|
|
26
|
+
if (tags['ShotInfo']) {
|
|
27
|
+
tags = objectAssign({}, tags, parseShotInfo(tags['ShotInfo'].value));
|
|
28
|
+
delete tags['ShotInfo'];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return tags;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseShotInfo(shotInfoData) {
|
|
35
|
+
const tags = {};
|
|
36
|
+
|
|
37
|
+
if (shotInfoData[SHOT_INFO_AUTO_ROTATE] !== undefined) {
|
|
38
|
+
tags['AutoRotate'] = {
|
|
39
|
+
value: shotInfoData[SHOT_INFO_AUTO_ROTATE],
|
|
40
|
+
description: getAutoRotateDescription(shotInfoData[SHOT_INFO_AUTO_ROTATE])
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return tags;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getAutoRotateDescription(autoRotate) {
|
|
48
|
+
if (autoRotate === 0) {
|
|
49
|
+
return 'None';
|
|
50
|
+
}
|
|
51
|
+
if (autoRotate === 1) {
|
|
52
|
+
return 'Rotate 90 CW';
|
|
53
|
+
}
|
|
54
|
+
if (autoRotate === 2) {
|
|
55
|
+
return 'Rotate 180';
|
|
56
|
+
}
|
|
57
|
+
if (autoRotate === 3) {
|
|
58
|
+
return 'Rotate 270 CW';
|
|
59
|
+
}
|
|
60
|
+
return 'Unknown';
|
|
61
|
+
}
|
package/src/constants.js
CHANGED
package/src/exif-reader.js
CHANGED
|
@@ -22,6 +22,7 @@ import IptcTags from './iptc-tags.js';
|
|
|
22
22
|
import XmpTags from './xmp-tags.js';
|
|
23
23
|
import PhotoshopTags from './photoshop-tags.js';
|
|
24
24
|
import IccTags from './icc-tags.js';
|
|
25
|
+
import CanonTags from './canon-tags.js';
|
|
25
26
|
import PngFileTags from './png-file-tags.js';
|
|
26
27
|
import PngTextTags from './png-text-tags.js';
|
|
27
28
|
import PngTags from './png-tags.js';
|
|
@@ -243,7 +244,7 @@ export function loadView(
|
|
|
243
244
|
|
|
244
245
|
if (Constants.USE_EXIF && hasExifData(tiffHeaderOffset)) {
|
|
245
246
|
foundMetaData = true;
|
|
246
|
-
const readTags = Tags.read(dataView, tiffHeaderOffset, includeUnknown);
|
|
247
|
+
const {tags: readTags, byteOrder} = Tags.read(dataView, tiffHeaderOffset, includeUnknown);
|
|
247
248
|
if (readTags.Thumbnail) {
|
|
248
249
|
tags.Thumbnail = readTags.Thumbnail;
|
|
249
250
|
delete readTags.Thumbnail;
|
|
@@ -300,6 +301,21 @@ export function loadView(
|
|
|
300
301
|
tags = objectAssign({}, tags, readIccTags);
|
|
301
302
|
}
|
|
302
303
|
}
|
|
304
|
+
|
|
305
|
+
if (Constants.USE_MAKER_NOTES) {
|
|
306
|
+
if (hasCanonData(readTags)) {
|
|
307
|
+
const readCanonTags = CanonTags.read(dataView, tiffHeaderOffset, readTags['MakerNote'].__offset, byteOrder, includeUnknown);
|
|
308
|
+
if (expanded) {
|
|
309
|
+
tags.makerNotes = readCanonTags;
|
|
310
|
+
} else {
|
|
311
|
+
tags = objectAssign({}, tags, readCanonTags);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (readTags['MakerNote']) {
|
|
317
|
+
delete readTags['MakerNote'].__offset;
|
|
318
|
+
}
|
|
303
319
|
}
|
|
304
320
|
|
|
305
321
|
if (Constants.USE_JPEG && Constants.USE_IPTC && hasIptcData(iptcDataOffset)) {
|
|
@@ -522,6 +538,11 @@ function hasIccData(iccDataOffsets) {
|
|
|
522
538
|
return Array.isArray(iccDataOffsets) && iccDataOffsets.length > 0;
|
|
523
539
|
}
|
|
524
540
|
|
|
541
|
+
function hasCanonData(tags) {
|
|
542
|
+
return tags['Make'] && tags['Make'].value && Array.isArray(tags['Make'].value) && tags['Make'].value[0] === 'Canon'
|
|
543
|
+
&& tags['MakerNote'] && tags['MakerNote'].__offset;
|
|
544
|
+
}
|
|
545
|
+
|
|
525
546
|
function hasMpfData(mpfDataOffset) {
|
|
526
547
|
return mpfDataOffset !== undefined;
|
|
527
548
|
}
|
package/src/png-text-tags.js
CHANGED
|
@@ -35,13 +35,13 @@ function read(dataView, pngTextChunks, async, includeUnknown) {
|
|
|
35
35
|
try {
|
|
36
36
|
if (Constants.USE_EXIF && isExifGroupTag(name, value)) {
|
|
37
37
|
return {
|
|
38
|
-
__exif: Tags.read(decodeRawData(value), EXIF_OFFSET, includeUnknown)
|
|
38
|
+
__exif: Tags.read(decodeRawData(value), EXIF_OFFSET, includeUnknown).tags
|
|
39
39
|
};
|
|
40
40
|
} else if (Constants.USE_IPTC && isIptcGroupTag(name, value)) {
|
|
41
41
|
return {
|
|
42
42
|
__iptc: IptcTags.read(decodeRawData(value), 0, includeUnknown)
|
|
43
43
|
};
|
|
44
|
-
} else if (name) {
|
|
44
|
+
} else if (name && !isExifGroupTag(name, value) && !isIptcGroupTag(name, value)) {
|
|
45
45
|
return {
|
|
46
46
|
[name]: {
|
|
47
47
|
value,
|
package/src/tag-names-0th-ifd.js
CHANGED
|
@@ -230,11 +230,26 @@ export default {
|
|
|
230
230
|
0x87b0: 'GeoTiffDoubleParams',
|
|
231
231
|
0x87b1: 'GeoTiffAsciiParams',
|
|
232
232
|
0x8825: 'GPS Info IFD Pointer',
|
|
233
|
-
0x9c9b:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
0x9c9b: {
|
|
234
|
+
name: 'XPTitle',
|
|
235
|
+
description: decodeXPValue,
|
|
236
|
+
},
|
|
237
|
+
0x9c9c: {
|
|
238
|
+
name: 'XPComment',
|
|
239
|
+
description: decodeXPValue
|
|
240
|
+
},
|
|
241
|
+
0x9c9d: {
|
|
242
|
+
name: 'XPAuthor',
|
|
243
|
+
description: decodeXPValue,
|
|
244
|
+
},
|
|
245
|
+
0x9c9e: {
|
|
246
|
+
name: 'XPKeywords',
|
|
247
|
+
description: decodeXPValue,
|
|
248
|
+
},
|
|
249
|
+
0x9c9f: {
|
|
250
|
+
name: 'XPSubject',
|
|
251
|
+
description: decodeXPValue,
|
|
252
|
+
},
|
|
238
253
|
0xa480: 'GDALMetadata',
|
|
239
254
|
0xa481: 'GDALNoData',
|
|
240
255
|
0xc4a5: 'PrintIM',
|
|
@@ -355,3 +370,12 @@ export default {
|
|
|
355
370
|
0xc7a7: 'NewRawImageDigest',
|
|
356
371
|
0xc7a8: 'RawToPreviewGain'
|
|
357
372
|
};
|
|
373
|
+
|
|
374
|
+
function decodeXPValue(value) {
|
|
375
|
+
// The XP tags are encoded as UCS-2 which uses two bytes per character but
|
|
376
|
+
// it's close to UTF-16 so we can use that to decode them.
|
|
377
|
+
// https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
|
|
378
|
+
const decodedValue = new TextDecoder('utf-16').decode(new Uint8Array(value));
|
|
379
|
+
// Some softwares pad the string with null characters so we remove them.
|
|
380
|
+
return decodedValue.replace(/\u0000+$/, ''); // eslint-disable-line no-control-regex
|
|
381
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
0x0004: {
|
|
7
|
+
'name': 'ShotInfo',
|
|
8
|
+
'description': (value) => value
|
|
9
|
+
},
|
|
10
|
+
};
|
package/src/tag-names.js
CHANGED
|
@@ -9,6 +9,7 @@ import TagNamesExifIfd from './tag-names-exif-ifd.js';
|
|
|
9
9
|
import TagNamesGpsIfd from './tag-names-gps-ifd.js';
|
|
10
10
|
import TagNamesInteroperabilityIfd from './tag-names-interoperability-ifd.js';
|
|
11
11
|
import TagNamesMpfIfd from './tag-names-mpf-ifd.js';
|
|
12
|
+
import TagNamesCanonIfd from './tag-names-canon-ifd.js';
|
|
12
13
|
|
|
13
14
|
const tagNames0thExifIfds = objectAssign({}, TagNames0thIfd, TagNamesExifIfd);
|
|
14
15
|
|
|
@@ -18,6 +19,7 @@ export const IFD_TYPE_EXIF = 'exif';
|
|
|
18
19
|
export const IFD_TYPE_GPS = 'gps';
|
|
19
20
|
export const IFD_TYPE_INTEROPERABILITY = 'interoperability';
|
|
20
21
|
export const IFD_TYPE_MPF = 'mpf';
|
|
22
|
+
export const IFD_TYPE_CANON = 'canon';
|
|
21
23
|
|
|
22
24
|
export default {
|
|
23
25
|
[IFD_TYPE_0TH]: tagNames0thExifIfds,
|
|
@@ -26,4 +28,5 @@ export default {
|
|
|
26
28
|
[IFD_TYPE_GPS]: TagNamesGpsIfd,
|
|
27
29
|
[IFD_TYPE_INTEROPERABILITY]: TagNamesInteroperabilityIfd,
|
|
28
30
|
[IFD_TYPE_MPF]: Constants.USE_MPF ? TagNamesMpfIfd : {},
|
|
31
|
+
[IFD_TYPE_CANON]: Constants.USE_MAKER_NOTES ? TagNamesCanonIfd : {},
|
|
29
32
|
};
|
package/src/tags-helpers.js
CHANGED
|
@@ -42,6 +42,9 @@ export function readIfd(dataView, ifdType, tiffHeaderOffset, offset, byteOrder,
|
|
|
42
42
|
'value': tag.value,
|
|
43
43
|
'description': tag.description
|
|
44
44
|
};
|
|
45
|
+
if (tag.name === 'MakerNote') {
|
|
46
|
+
tags[tag.name].__offset = tag.__offset;
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
offset += FIELD_SIZE;
|
|
@@ -74,15 +77,17 @@ function readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, include
|
|
|
74
77
|
const tagType = Types.getShortAt(dataView, offset + TAG_TYPE_OFFSET, byteOrder);
|
|
75
78
|
const tagCount = Types.getLongAt(dataView, offset + TAG_COUNT_OFFSET, byteOrder);
|
|
76
79
|
let tagValue;
|
|
80
|
+
let tagValueOffset;
|
|
77
81
|
|
|
78
82
|
if (Types.typeSizes[tagType] === undefined || (!includeUnknown && TagNames[ifdType][tagCode] === undefined)) {
|
|
79
83
|
return undefined;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
if (tagValueFitsInOffsetSlot(tagType, tagCount)) {
|
|
83
|
-
|
|
87
|
+
tagValueOffset = offset + TAG_VALUE_OFFSET;
|
|
88
|
+
tagValue = getTagValue(dataView, tagValueOffset, tagType, tagCount, byteOrder);
|
|
84
89
|
} else {
|
|
85
|
-
|
|
90
|
+
tagValueOffset = Types.getLongAt(dataView, offset + TAG_VALUE_OFFSET, byteOrder);
|
|
86
91
|
if (tagValueFitsInDataView(dataView, tiffHeaderOffset, tagValueOffset, tagType, tagCount)) {
|
|
87
92
|
const forceByteType = tagCode === TAG_CODE_IPTC_NAA;
|
|
88
93
|
tagValue = getTagValue(dataView, tiffHeaderOffset + tagValueOffset, tagType, tagCount, byteOrder, forceByteType);
|
|
@@ -120,7 +125,8 @@ function readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, include
|
|
|
120
125
|
id: tagCode,
|
|
121
126
|
name: tagName,
|
|
122
127
|
value: tagValue,
|
|
123
|
-
description: tagDescription
|
|
128
|
+
description: tagDescription,
|
|
129
|
+
__offset: tagValueOffset
|
|
124
130
|
};
|
|
125
131
|
}
|
|
126
132
|
|
package/src/tags.js
CHANGED
|
@@ -22,7 +22,7 @@ function read(dataView, tiffHeaderOffset, includeUnknown) {
|
|
|
22
22
|
tags = readGpsIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown);
|
|
23
23
|
tags = readInteroperabilityIfd(tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown);
|
|
24
24
|
|
|
25
|
-
return tags;
|
|
25
|
+
return {tags, byteOrder};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown) {
|
package/webpack.config.js
CHANGED
|
@@ -81,7 +81,7 @@ module.exports = {
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
|
-
test: /[/\\](exif-reader|image-header-?(tiff|jpeg|png|heic|avif|iso-bmff|webp|gif)?|tags|tag-names)\.js$/,
|
|
84
|
+
test: /[/\\](exif-reader|image-header-?(tiff|jpeg|png|heic|avif|iso-bmff|webp|gif)?|tags|tag-names|tags-helpers|png-text-tags)\.js$/,
|
|
85
85
|
loader: 'string-replace-loader',
|
|
86
86
|
options: {
|
|
87
87
|
multiple: getConstantReplacements(includedModules)
|
|
@@ -100,6 +100,8 @@ function parseConfig({include: includesConfig, exclude: excludesConfig}) {
|
|
|
100
100
|
'iptc',
|
|
101
101
|
'xmp',
|
|
102
102
|
'icc',
|
|
103
|
+
'photoshop',
|
|
104
|
+
'maker_notes',
|
|
103
105
|
'mpf',
|
|
104
106
|
'thumbnail',
|
|
105
107
|
'tiff',
|
|
@@ -166,6 +168,9 @@ function getConfig() {
|
|
|
166
168
|
if (packageJson.include.thumbnail) {
|
|
167
169
|
packageJson.include.exif.push('JPEGInterchangeFormat', 'JPEGInterchangeFormatLength');
|
|
168
170
|
}
|
|
171
|
+
if (packageJson.include.maker_notes) {
|
|
172
|
+
packageJson.include.exif.push('MakerNote', 'Make');
|
|
173
|
+
}
|
|
169
174
|
}
|
|
170
175
|
return {include: packageJson.include};
|
|
171
176
|
}
|