exifreader 4.13.2 → 4.14.1
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/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +22 -2
- package/package.json +1 -1
- package/src/exif-reader.js +29 -1
- package/src/image-header-webp.js +6 -1
- package/src/image-header.js +10 -5
- package/src/vp8x-tags.js +55 -0
package/exif-reader.d.ts
CHANGED
|
@@ -81,6 +81,25 @@ interface PngTextTags {
|
|
|
81
81
|
[name: string]: PngTextTag
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
interface RiffTags {
|
|
85
|
+
'Alpha'?: {
|
|
86
|
+
value: 0 | 1,
|
|
87
|
+
description: 'No' | 'Yes'
|
|
88
|
+
},
|
|
89
|
+
'Animation'?: {
|
|
90
|
+
value: 0 | 1,
|
|
91
|
+
description: 'No' | 'Yes'
|
|
92
|
+
},
|
|
93
|
+
'ImageWidth'?: {
|
|
94
|
+
value: number,
|
|
95
|
+
description: string
|
|
96
|
+
},
|
|
97
|
+
'ImageHeight'?: {
|
|
98
|
+
value: number,
|
|
99
|
+
description: string
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
84
103
|
interface NumberFileTag {
|
|
85
104
|
description: string,
|
|
86
105
|
value: number
|
|
@@ -153,6 +172,7 @@ interface ExpandedTags {
|
|
|
153
172
|
iptc?: ExifTags,
|
|
154
173
|
xmp?: { _raw: string } & XmpTags,
|
|
155
174
|
icc?: IccTags,
|
|
175
|
+
riff?: RiffTags,
|
|
156
176
|
Thumbnail?: ThumbnailTags,
|
|
157
177
|
gps?: GpsTags
|
|
158
178
|
}
|
|
@@ -453,9 +473,9 @@ interface IccTags {
|
|
|
453
473
|
[name: string]: ValueTag;
|
|
454
474
|
}
|
|
455
475
|
|
|
456
|
-
export type Tags = XmpTags & IccTags & PngTags & {
|
|
476
|
+
export type Tags = XmpTags & IccTags & PngTags & RiffTags & {
|
|
457
477
|
'Thumbnail'?: ThumbnailTags;
|
|
458
478
|
'Images'?: MPFImageTags[],
|
|
459
479
|
} & {
|
|
460
480
|
[K in keyof ExifTags]: ExifTags[K] | XmpTag;
|
|
461
|
-
}
|
|
481
|
+
}
|
package/package.json
CHANGED
package/src/exif-reader.js
CHANGED
|
@@ -23,6 +23,7 @@ import IccTags from './icc-tags.js';
|
|
|
23
23
|
import PngFileTags from './png-file-tags.js';
|
|
24
24
|
import PngTextTags from './png-text-tags.js';
|
|
25
25
|
import PngTags from './png-tags.js';
|
|
26
|
+
import Vp8xTags from './vp8x-tags.js';
|
|
26
27
|
import Thumbnail from './thumbnail.js';
|
|
27
28
|
import exifErrors from './errors.js';
|
|
28
29
|
|
|
@@ -196,6 +197,7 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
196
197
|
let tags = {};
|
|
197
198
|
|
|
198
199
|
const {
|
|
200
|
+
fileType,
|
|
199
201
|
fileDataOffset,
|
|
200
202
|
jfifDataOffset,
|
|
201
203
|
tiffHeaderOffset,
|
|
@@ -205,7 +207,8 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
205
207
|
mpfDataOffset,
|
|
206
208
|
pngHeaderOffset,
|
|
207
209
|
pngTextChunks,
|
|
208
|
-
pngChunkOffsets
|
|
210
|
+
pngChunkOffsets,
|
|
211
|
+
vp8xChunkOffset,
|
|
209
212
|
} = ImageHeader.parseAppMarkers(dataView);
|
|
210
213
|
|
|
211
214
|
if (Constants.USE_JPEG && Constants.USE_FILE && hasFileData(fileDataOffset)) {
|
|
@@ -353,6 +356,16 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
353
356
|
}
|
|
354
357
|
}
|
|
355
358
|
|
|
359
|
+
if (Constants.USE_WEBP && hasVp8xData(vp8xChunkOffset)) {
|
|
360
|
+
foundMetaData = true;
|
|
361
|
+
const readTags = Vp8xTags.read(dataView, vp8xChunkOffset);
|
|
362
|
+
if (expanded) {
|
|
363
|
+
tags.riff = !tags.riff ? readTags : objectAssign({}, tags.riff, readTags);
|
|
364
|
+
} else {
|
|
365
|
+
tags = objectAssign({}, tags, readTags);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
356
369
|
const thumbnail = (Constants.USE_JPEG || Constants.USE_WEBP)
|
|
357
370
|
&& Constants.USE_EXIF
|
|
358
371
|
&& Constants.USE_THUMBNAIL
|
|
@@ -364,6 +377,17 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
364
377
|
delete tags.Thumbnail;
|
|
365
378
|
}
|
|
366
379
|
|
|
380
|
+
if (fileType) {
|
|
381
|
+
if (expanded) {
|
|
382
|
+
if (!tags.file) {
|
|
383
|
+
tags.file = {};
|
|
384
|
+
}
|
|
385
|
+
tags.file.FileType = fileType;
|
|
386
|
+
} else {
|
|
387
|
+
tags.FileType = fileType;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
367
391
|
if (!foundMetaData) {
|
|
368
392
|
throw new exifErrors.MetadataMissingError();
|
|
369
393
|
}
|
|
@@ -450,3 +474,7 @@ function hasPngTextData(pngTextChunks) {
|
|
|
450
474
|
function hasPngData(pngChunkOffsets) {
|
|
451
475
|
return pngChunkOffsets !== undefined;
|
|
452
476
|
}
|
|
477
|
+
|
|
478
|
+
function hasVp8xData(vp8xChunkOffset) {
|
|
479
|
+
return vp8xChunkOffset !== undefined;
|
|
480
|
+
}
|
package/src/image-header-webp.js
CHANGED
|
@@ -31,6 +31,7 @@ function findOffsets(dataView) {
|
|
|
31
31
|
let tiffHeaderOffset;
|
|
32
32
|
let xmpChunks;
|
|
33
33
|
let iccChunks;
|
|
34
|
+
let vp8xChunkOffset;
|
|
34
35
|
|
|
35
36
|
while (offset + CHUNK_HEADER_SIZE < dataView.byteLength) {
|
|
36
37
|
const chunkId = getStringFromDataView(dataView, offset, 4);
|
|
@@ -57,6 +58,9 @@ function findOffsets(dataView) {
|
|
|
57
58
|
chunkNumber: 1,
|
|
58
59
|
chunksTotal: 1
|
|
59
60
|
}];
|
|
61
|
+
} else if (chunkId === 'VP8X') {
|
|
62
|
+
hasAppMarkers = true;
|
|
63
|
+
vp8xChunkOffset = offset + CHUNK_HEADER_SIZE;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
offset += CHUNK_HEADER_SIZE + (chunkSize % 2 === 0 ? chunkSize : chunkSize + 1);
|
|
@@ -66,6 +70,7 @@ function findOffsets(dataView) {
|
|
|
66
70
|
hasAppMarkers,
|
|
67
71
|
tiffHeaderOffset,
|
|
68
72
|
xmpChunks,
|
|
69
|
-
iccChunks
|
|
73
|
+
iccChunks,
|
|
74
|
+
vp8xChunkOffset
|
|
70
75
|
};
|
|
71
76
|
}
|
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 {objectAssign} from './utils.js';
|
|
11
12
|
|
|
12
13
|
export default {
|
|
13
14
|
parseAppMarkers
|
|
@@ -15,24 +16,28 @@ export default {
|
|
|
15
16
|
|
|
16
17
|
function parseAppMarkers(dataView) {
|
|
17
18
|
if (Constants.USE_TIFF && Tiff.isTiffFile(dataView)) {
|
|
18
|
-
return Tiff.findTiffOffsets();
|
|
19
|
+
return addFileType(Tiff.findTiffOffsets(), 'tiff', 'TIFF');
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
if (Constants.USE_JPEG && Jpeg.isJpegFile(dataView)) {
|
|
22
|
-
return Jpeg.findJpegOffsets(dataView);
|
|
23
|
+
return addFileType(Jpeg.findJpegOffsets(dataView), 'jpeg', 'JPEG');
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
if (Constants.USE_PNG && Png.isPngFile(dataView)) {
|
|
26
|
-
return Png.findPngOffsets(dataView);
|
|
27
|
+
return addFileType(Png.findPngOffsets(dataView), 'png', 'PNG');
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
if (Constants.USE_HEIC && Heic.isHeicFile(dataView)) {
|
|
30
|
-
return Heic.findHeicOffsets(dataView);
|
|
31
|
+
return addFileType(Heic.findHeicOffsets(dataView), 'heic', 'HEIC');
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
if (Constants.USE_WEBP && Webp.isWebpFile(dataView)) {
|
|
34
|
-
return Webp.findOffsets(dataView);
|
|
35
|
+
return addFileType(Webp.findOffsets(dataView), 'webp', 'WebP');
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
throw new Error('Invalid image format');
|
|
38
39
|
}
|
|
40
|
+
|
|
41
|
+
function addFileType(offsets, fileType, fileTypeDescription) {
|
|
42
|
+
return objectAssign({}, offsets, {fileType: {value: fileType, description: fileTypeDescription}});
|
|
43
|
+
}
|
package/src/vp8x-tags.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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 Types from './types.js';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
read
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const IMAGE_WIDTH_OFFSET = 4;
|
|
12
|
+
const IMAGE_HEIGHT_OFFSET = 7;
|
|
13
|
+
|
|
14
|
+
// https://developers.google.com/speed/webp/docs/riff_container#extended_file_format
|
|
15
|
+
function read(dataView, chunkOffset) {
|
|
16
|
+
const tags = {};
|
|
17
|
+
|
|
18
|
+
const flags = Types.getByteAt(dataView, chunkOffset);
|
|
19
|
+
|
|
20
|
+
tags['Alpha'] = getAlpha(flags);
|
|
21
|
+
tags['Animation'] = getAnimation(flags);
|
|
22
|
+
tags['ImageWidth'] = getThreeByteValue(dataView, chunkOffset + IMAGE_WIDTH_OFFSET);
|
|
23
|
+
tags['ImageHeight'] = getThreeByteValue(dataView, chunkOffset + IMAGE_HEIGHT_OFFSET);
|
|
24
|
+
|
|
25
|
+
return tags;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getAlpha(flags) {
|
|
29
|
+
const value = flags & 0x10;
|
|
30
|
+
return {
|
|
31
|
+
value: value ? 1 : 0,
|
|
32
|
+
description: value ? 'Yes' : 'No'
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getAnimation(flags) {
|
|
37
|
+
const value = flags & 0x02;
|
|
38
|
+
return {
|
|
39
|
+
value: value ? 1 : 0,
|
|
40
|
+
description: value ? 'Yes' : 'No'
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getThreeByteValue(dataView, offset) {
|
|
45
|
+
// Values are stored little-endian.
|
|
46
|
+
const value = Types.getByteAt(dataView, offset)
|
|
47
|
+
+ 256 * Types.getByteAt(dataView, offset + 1)
|
|
48
|
+
+ 256 * 256 * Types.getByteAt(dataView, offset + 2)
|
|
49
|
+
+ 1; // Value is 1-based, i.e. a value of 7 means 8px.
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
value,
|
|
53
|
+
description: value + 'px'
|
|
54
|
+
};
|
|
55
|
+
}
|