exifreader 4.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.18.0",
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:types 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": 91,
72
+ "branches": 90,
73
73
  "functions": 98,
74
74
  "lines": 95,
75
75
  "reporter": [
package/src/constants.js CHANGED
@@ -17,5 +17,6 @@ export default {
17
17
  USE_JPEG: true,
18
18
  USE_PNG: true,
19
19
  USE_HEIC: true,
20
- USE_WEBP: true
20
+ USE_WEBP: true,
21
+ USE_GIF: true
21
22
  };
@@ -26,6 +26,7 @@ import PngFileTags from './png-file-tags.js';
26
26
  import PngTextTags from './png-text-tags.js';
27
27
  import PngTags from './png-tags.js';
28
28
  import Vp8xTags from './vp8x-tags.js';
29
+ import GifFileTags from './gif-file-tags.js';
29
30
  import Thumbnail from './thumbnail.js';
30
31
  import exifErrors from './errors.js';
31
32
 
@@ -211,6 +212,7 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
211
212
  pngTextChunks,
212
213
  pngChunkOffsets,
213
214
  vp8xChunkOffset,
215
+ gifHeaderOffset
214
216
  } = ImageHeader.parseAppMarkers(dataView);
215
217
 
216
218
  if (Constants.USE_JPEG && Constants.USE_FILE && hasFileData(fileDataOffset)) {
@@ -377,6 +379,16 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
377
379
  }
378
380
  }
379
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
+
380
392
  const thumbnail = (Constants.USE_JPEG || Constants.USE_WEBP)
381
393
  && Constants.USE_EXIF
382
394
  && Constants.USE_THUMBNAIL
@@ -489,3 +501,7 @@ function hasPngData(pngChunkOffsets) {
489
501
  function hasVp8xData(vp8xChunkOffset) {
490
502
  return vp8xChunkOffset !== undefined;
491
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
+ }
@@ -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
 
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|webp)?|tags|tag-names)\.js$/,
84
+ test: /\/(exif-reader|image-header-?(tiff|jpeg|png|heic|webp|gif)?|tags|tag-names)\.js$/,
85
85
  loader: 'string-replace-loader',
86
86
  options: {
87
87
  multiple: getConstantReplacements(includedModules)
@@ -106,7 +106,8 @@ function parseConfig({include: includesConfig, exclude: excludesConfig}) {
106
106
  'jpeg',
107
107
  'png',
108
108
  'heic',
109
- 'webp'
109
+ 'webp',
110
+ 'gif'
110
111
  ];
111
112
 
112
113
  if (includesConfig) {