exifreader 4.17.0 → 4.19.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 +23 -11
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +12 -1
- package/package.json +3 -3
- package/src/constants.js +3 -1
- package/src/exif-reader.js +26 -0
- package/src/gif-file-tags.js +116 -0
- package/src/image-header-gif.js +23 -0
- package/src/image-header.js +5 -0
- package/src/photoshop-tag-names.js +1062 -0
- package/src/photoshop-tags.js +67 -0
- package/src/tag-names-exif-ifd.js +1 -0
- package/src/utils.js +33 -0
- package/webpack.config.js +3 -2
package/exif-reader.d.ts
CHANGED
|
@@ -124,6 +124,8 @@ type NumberArrayTag = TypedTag<number[]>
|
|
|
124
124
|
|
|
125
125
|
type StringArrayTag = TypedTag<string[]>
|
|
126
126
|
|
|
127
|
+
type StringTag = TypedTag<string>;
|
|
128
|
+
|
|
127
129
|
interface ValueTag {
|
|
128
130
|
description: string,
|
|
129
131
|
value: string
|
|
@@ -175,6 +177,7 @@ interface ExpandedTags {
|
|
|
175
177
|
riff?: RiffTags,
|
|
176
178
|
Thumbnail?: ThumbnailTags,
|
|
177
179
|
gps?: GpsTags
|
|
180
|
+
photoshop?: PhotoshopTags;
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
interface GpsTags {
|
|
@@ -216,6 +219,14 @@ interface MPFImageTags {
|
|
|
216
219
|
base64: string
|
|
217
220
|
}
|
|
218
221
|
|
|
222
|
+
interface PhotoshopTags {
|
|
223
|
+
// CaptionDigest: StringTag;
|
|
224
|
+
// PrintInformation: StringTag;
|
|
225
|
+
// PrintStyle: StringTag;
|
|
226
|
+
PathInformation: StringTag;
|
|
227
|
+
ClippingPathName: StringTag;
|
|
228
|
+
}
|
|
229
|
+
|
|
219
230
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer): Tags;
|
|
220
231
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded: true, includeUnknown?: boolean, length?: number}): ExpandedTags;
|
|
221
232
|
export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: {expanded?: false, includeUnknown?: boolean, length?: number}): Tags;
|
|
@@ -473,7 +484,7 @@ interface IccTags {
|
|
|
473
484
|
[name: string]: ValueTag;
|
|
474
485
|
}
|
|
475
486
|
|
|
476
|
-
export type Tags = XmpTags & IccTags & PngTags & RiffTags & {
|
|
487
|
+
export type Tags = XmpTags & IccTags & PngTags & RiffTags & PhotoshopTags & {
|
|
477
488
|
'Thumbnail'?: ThumbnailTags;
|
|
478
489
|
'Images'?: MPFImageTags[],
|
|
479
490
|
} & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"test:e2e": "cypress run",
|
|
63
63
|
"test:types": "tsc --noEmit --project test/types",
|
|
64
64
|
"test:all": "npm-run-all lint test:types coverage test:e2e test:build test:build:custom",
|
|
65
|
-
"pre-commit": "npm-run-all lint test test:build",
|
|
65
|
+
"pre-commit": "npm-run-all lint test:types coverage test:build",
|
|
66
66
|
"postinstall": "node bin/build.js --only-with-config",
|
|
67
67
|
"prepare": "husky install"
|
|
68
68
|
},
|
|
69
69
|
"nyc": {
|
|
70
70
|
"check-coverage": true,
|
|
71
71
|
"statements": 95,
|
|
72
|
-
"branches":
|
|
72
|
+
"branches": 90,
|
|
73
73
|
"functions": 98,
|
|
74
74
|
"lines": 95,
|
|
75
75
|
"reporter": [
|
package/src/constants.js
CHANGED
|
@@ -11,10 +11,12 @@ export default {
|
|
|
11
11
|
USE_XMP: true,
|
|
12
12
|
USE_ICC: true,
|
|
13
13
|
USE_MPF: true,
|
|
14
|
+
USE_PHOTOSHOP: true,
|
|
14
15
|
USE_THUMBNAIL: true,
|
|
15
16
|
USE_TIFF: true,
|
|
16
17
|
USE_JPEG: true,
|
|
17
18
|
USE_PNG: true,
|
|
18
19
|
USE_HEIC: true,
|
|
19
|
-
USE_WEBP: true
|
|
20
|
+
USE_WEBP: true,
|
|
21
|
+
USE_GIF: true
|
|
20
22
|
};
|
package/src/exif-reader.js
CHANGED
|
@@ -20,11 +20,13 @@ import FileTags from './file-tags.js';
|
|
|
20
20
|
import JfifTags from './jfif-tags.js';
|
|
21
21
|
import IptcTags from './iptc-tags.js';
|
|
22
22
|
import XmpTags from './xmp-tags.js';
|
|
23
|
+
import PhotoshopTags from './photoshop-tags.js';
|
|
23
24
|
import IccTags from './icc-tags.js';
|
|
24
25
|
import PngFileTags from './png-file-tags.js';
|
|
25
26
|
import PngTextTags from './png-text-tags.js';
|
|
26
27
|
import PngTags from './png-tags.js';
|
|
27
28
|
import Vp8xTags from './vp8x-tags.js';
|
|
29
|
+
import GifFileTags from './gif-file-tags.js';
|
|
28
30
|
import Thumbnail from './thumbnail.js';
|
|
29
31
|
import exifErrors from './errors.js';
|
|
30
32
|
|
|
@@ -210,6 +212,7 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
210
212
|
pngTextChunks,
|
|
211
213
|
pngChunkOffsets,
|
|
212
214
|
vp8xChunkOffset,
|
|
215
|
+
gifHeaderOffset
|
|
213
216
|
} = ImageHeader.parseAppMarkers(dataView);
|
|
214
217
|
|
|
215
218
|
if (Constants.USE_JPEG && Constants.USE_FILE && hasFileData(fileDataOffset)) {
|
|
@@ -266,6 +269,15 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
|
|
272
|
+
if (Constants.USE_PHOTOSHOP && readTags['ImageSourceData']) {
|
|
273
|
+
const readPhotoshopTags = PhotoshopTags.read(readTags['PhotoshopSettings'].value, includeUnknown);
|
|
274
|
+
if (expanded) {
|
|
275
|
+
tags.photoshop = readPhotoshopTags;
|
|
276
|
+
} else {
|
|
277
|
+
tags = objectAssign({}, tags, readPhotoshopTags);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
269
281
|
if (Constants.USE_TIFF && Constants.USE_ICC && readTags['ICC_Profile'] && !hasIccData(iccChunks)) {
|
|
270
282
|
const readIccTags = IccTags.read(
|
|
271
283
|
readTags['ICC_Profile'].value,
|
|
@@ -367,6 +379,16 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
367
379
|
}
|
|
368
380
|
}
|
|
369
381
|
|
|
382
|
+
if (Constants.USE_GIF && hasGifFileData(gifHeaderOffset)) {
|
|
383
|
+
foundMetaData = true;
|
|
384
|
+
const readTags = GifFileTags.read(dataView, gifHeaderOffset);
|
|
385
|
+
if (expanded) {
|
|
386
|
+
tags.gif = !tags.gif ? readTags : objectAssign({}, tags.gif, readTags);
|
|
387
|
+
} else {
|
|
388
|
+
tags = objectAssign({}, tags, readTags);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
370
392
|
const thumbnail = (Constants.USE_JPEG || Constants.USE_WEBP)
|
|
371
393
|
&& Constants.USE_EXIF
|
|
372
394
|
&& Constants.USE_THUMBNAIL
|
|
@@ -479,3 +501,7 @@ function hasPngData(pngChunkOffsets) {
|
|
|
479
501
|
function hasVp8xData(vp8xChunkOffset) {
|
|
480
502
|
return vp8xChunkOffset !== undefined;
|
|
481
503
|
}
|
|
504
|
+
|
|
505
|
+
function hasGifFileData(gifHeaderOffset) {
|
|
506
|
+
return gifHeaderOffset !== undefined;
|
|
507
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
// https://www.w3.org/Graphics/GIF/spec-gif87.txt
|
|
6
|
+
// https://www.w3.org/Graphics/GIF/spec-gif89a.txt
|
|
7
|
+
|
|
8
|
+
import {getStringFromDataView} from './utils.js';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
read
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function read(dataView) {
|
|
15
|
+
return {
|
|
16
|
+
'GIF Version': getGifVersion(dataView),
|
|
17
|
+
'Image Width': getImageWidth(dataView),
|
|
18
|
+
'Image Height': getImageHeight(dataView),
|
|
19
|
+
'Global Color Map': getGlobalColorMap(dataView),
|
|
20
|
+
'Bits Per Pixel': getBitDepth(dataView),
|
|
21
|
+
'Color Resolution Depth': getColorResolution(dataView)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getGifVersion(dataView) {
|
|
26
|
+
const OFFSET = 3;
|
|
27
|
+
const SIZE = 3;
|
|
28
|
+
|
|
29
|
+
if (OFFSET + SIZE > dataView.byteLength) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const value = getStringFromDataView(dataView, OFFSET, SIZE);
|
|
34
|
+
return {
|
|
35
|
+
value,
|
|
36
|
+
description: value
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getImageWidth(dataView) {
|
|
41
|
+
const OFFSET = 6;
|
|
42
|
+
const SIZE = 2;
|
|
43
|
+
|
|
44
|
+
if (OFFSET + SIZE > dataView.byteLength) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const value = dataView.getUint16(OFFSET, true);
|
|
49
|
+
return {
|
|
50
|
+
value,
|
|
51
|
+
description: `${value}px`
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getImageHeight(dataView) {
|
|
56
|
+
const OFFSET = 8;
|
|
57
|
+
const SIZE = 2;
|
|
58
|
+
|
|
59
|
+
if (OFFSET + SIZE > dataView.byteLength) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const value = dataView.getUint16(OFFSET, true);
|
|
64
|
+
return {
|
|
65
|
+
value,
|
|
66
|
+
description: `${value}px`
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getGlobalColorMap(dataView) {
|
|
71
|
+
const OFFSET = 10;
|
|
72
|
+
const SIZE = 1;
|
|
73
|
+
|
|
74
|
+
if (OFFSET + SIZE > dataView.byteLength) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const byteValue = dataView.getUint8(OFFSET);
|
|
79
|
+
const value = (byteValue & 0b10000000) >>> 7;
|
|
80
|
+
return {
|
|
81
|
+
value,
|
|
82
|
+
description: value === 1 ? 'Yes' : 'No'
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getColorResolution(dataView) {
|
|
87
|
+
const OFFSET = 10;
|
|
88
|
+
const SIZE = 1;
|
|
89
|
+
|
|
90
|
+
if (OFFSET + SIZE > dataView.byteLength) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const byteValue = dataView.getUint8(OFFSET);
|
|
95
|
+
const value = ((byteValue & 0b01110000) >>> 4) + 1; // Zero-based.
|
|
96
|
+
return {
|
|
97
|
+
value,
|
|
98
|
+
description: `${value} ${value === 1 ? 'bit' : 'bits'}`
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getBitDepth(dataView) {
|
|
103
|
+
const OFFSET = 10;
|
|
104
|
+
const SIZE = 1;
|
|
105
|
+
|
|
106
|
+
if (OFFSET + SIZE > dataView.byteLength) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const byteValue = dataView.getUint8(OFFSET);
|
|
111
|
+
const value = (byteValue & 0b00000111) + 1; // Zero-based.
|
|
112
|
+
return {
|
|
113
|
+
value,
|
|
114
|
+
description: `${value} ${value === 1 ? 'bit' : 'bits'}`
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import {getStringFromDataView} from './utils.js';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
isGifFile,
|
|
9
|
+
findOffsets
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const GIF_SIGNATURE_SIZE = 6;
|
|
13
|
+
const GIF_SIGNATURES = ['GIF87a', 'GIF89a'];
|
|
14
|
+
|
|
15
|
+
function isGifFile(dataView) {
|
|
16
|
+
return !!dataView && GIF_SIGNATURES.includes(getStringFromDataView(dataView, 0, GIF_SIGNATURE_SIZE));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function findOffsets() {
|
|
20
|
+
return {
|
|
21
|
+
gifHeaderOffset: 0
|
|
22
|
+
};
|
|
23
|
+
}
|
package/src/image-header.js
CHANGED
|
@@ -8,6 +8,7 @@ import Jpeg from './image-header-jpeg.js';
|
|
|
8
8
|
import Png from './image-header-png.js';
|
|
9
9
|
import Heic from './image-header-heic.js';
|
|
10
10
|
import Webp from './image-header-webp.js';
|
|
11
|
+
import Gif from './image-header-gif.js';
|
|
11
12
|
import {objectAssign} from './utils.js';
|
|
12
13
|
|
|
13
14
|
export default {
|
|
@@ -35,6 +36,10 @@ function parseAppMarkers(dataView) {
|
|
|
35
36
|
return addFileType(Webp.findOffsets(dataView), 'webp', 'WebP');
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
if (Constants.USE_GIF && Gif.isGifFile(dataView)) {
|
|
40
|
+
return addFileType(Gif.findOffsets(dataView), 'gif', 'GIF');
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
throw new Error('Invalid image format');
|
|
39
44
|
}
|
|
40
45
|
|