exifreader 4.9.2 → 4.10.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
@@ -53,6 +53,15 @@ interface PngFileTags {
53
53
  }
54
54
  }
55
55
 
56
+ interface PngTextTag {
57
+ description: string,
58
+ value: string
59
+ }
60
+
61
+ interface PngTextTags {
62
+ [name: string]: PngTextTag
63
+ }
64
+
56
65
  interface NumberFileTag {
57
66
  description: string,
58
67
  value: number
@@ -129,6 +138,7 @@ interface ExpandedTags {
129
138
  file?: FileTags,
130
139
  jfif?: JfifTags,
131
140
  pngFile?: PngFileTags,
141
+ pngText?: PngTextTags,
132
142
  exif?: Tags,
133
143
  iptc?: Tags,
134
144
  xmp?: { _raw: string } & XmpTags,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.9.2",
3
+ "version": "4.10.0",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -21,6 +21,7 @@ import IptcTags from './iptc-tags.js';
21
21
  import XmpTags from './xmp-tags.js';
22
22
  import IccTags from './icc-tags.js';
23
23
  import PngFileTags from './png-file-tags.js';
24
+ import PngTextTags from './png-text-tags.js';
24
25
  import Thumbnail from './thumbnail.js';
25
26
  import exifErrors from './errors.js';
26
27
 
@@ -193,7 +194,8 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
193
194
  xmpChunks,
194
195
  iccChunks,
195
196
  mpfDataOffset,
196
- pngHeaderOffset
197
+ pngHeaderOffset,
198
+ pngTextChunks
197
199
  } = ImageHeader.parseAppMarkers(dataView);
198
200
 
199
201
  if (Constants.USE_JPEG && Constants.USE_FILE && hasFileData(fileDataOffset)) {
@@ -319,6 +321,16 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
319
321
  }
320
322
  }
321
323
 
324
+ if (Constants.USE_PNG && hasPngTextData(pngTextChunks)) {
325
+ foundMetaData = true;
326
+ const readTags = PngTextTags.read(dataView, pngTextChunks);
327
+ if (expanded) {
328
+ tags.pngText = readTags;
329
+ } else {
330
+ tags = objectAssign({}, tags, readTags);
331
+ }
332
+ }
333
+
322
334
  const thumbnail = (Constants.USE_JPEG || Constants.USE_WEBP)
323
335
  && Constants.USE_EXIF
324
336
  && Constants.USE_THUMBNAIL
@@ -408,3 +420,7 @@ function hasMpfData(mpfDataOffset) {
408
420
  function hasPngFileData(pngFileDataOffset) {
409
421
  return pngFileDataOffset !== undefined;
410
422
  }
423
+
424
+ function hasPngTextData(pngTextChunks) {
425
+ return pngTextChunks !== undefined;
426
+ }
@@ -44,6 +44,12 @@ function findPngOffsets(dataView) {
44
44
  length: dataView.getUint32(offset + PNG_CHUNK_LENGTH_OFFSET) - (dataOffset - (offset + PNG_CHUNK_DATA_OFFSET))
45
45
  }];
46
46
  }
47
+ } else if (isPngTextChunk(dataView, offset)) {
48
+ offsets.hasAppMarkers = true;
49
+ if (!offsets.pngTextChunks) {
50
+ offsets.pngTextChunks = [];
51
+ }
52
+ offsets.pngTextChunks.push({length: dataView.getUint32(offset + PNG_CHUNK_LENGTH_OFFSET), offset: offset + PNG_CHUNK_DATA_OFFSET});
47
53
  }
48
54
 
49
55
  offset += dataView.getUint32(offset + PNG_CHUNK_LENGTH_OFFSET)
@@ -66,6 +72,11 @@ function isPngXmpChunk(dataView, offset) {
66
72
  && (getStringFromDataView(dataView, offset + PNG_CHUNK_DATA_OFFSET, PNG_XMP_PREFIX.length) === PNG_XMP_PREFIX);
67
73
  }
68
74
 
75
+ function isPngTextChunk(dataView, offset) {
76
+ const PNG_CHUNK_TYPE_TEXTUAL = 'tEXt';
77
+ return getStringFromDataView(dataView, offset + PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_TYPE_SIZE) === PNG_CHUNK_TYPE_TEXTUAL;
78
+ }
79
+
69
80
  function getPngXmpDataOffset(dataView, offset) {
70
81
  const COMPRESSION_FLAG_SIZE = 1;
71
82
  const COMPRESSION_METHOD_SIZE = 1;
@@ -0,0 +1,43 @@
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 {getStringValueFromArray} from './utils.js';
6
+
7
+ export default {
8
+ read
9
+ };
10
+
11
+ function read(dataView, pngTextChunks) {
12
+ return pngTextChunks.reduce((tags, {length, offset}) => {
13
+ const {name, value} = getNameAndValue(dataView, offset, length);
14
+ tags[name] = {
15
+ value,
16
+ description: value
17
+ };
18
+ return tags;
19
+ }, {});
20
+ }
21
+
22
+ function getNameAndValue(dataView, offset, length) {
23
+ const nameChars = [];
24
+ const valueChars = [];
25
+ let foundNullDivider = false;
26
+ for (let i = 0; i < length && offset + i < dataView.byteLength; i++) {
27
+ const byte = dataView.getUint8(offset + i);
28
+ if (byte === 0) {
29
+ foundNullDivider = true;
30
+ } else {
31
+ if (!foundNullDivider) {
32
+ nameChars.push(byte);
33
+ } else {
34
+ valueChars.push(byte);
35
+ }
36
+ }
37
+ }
38
+
39
+ return {
40
+ name: getStringValueFromArray(nameChars),
41
+ value: getStringValueFromArray(valueChars)
42
+ };
43
+ }