exifreader 4.30.0 → 4.31.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 +2 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +4 -0
- package/package.json +2 -2
- package/src/composite.js +88 -5
- package/src/exif-reader.js +1 -1
- package/src/tag-names-common.js +8 -0
- package/src/tag-names-exif-ifd.js +1 -6
package/exif-reader.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.31.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"string-replace-loader": "^3.1.0",
|
|
46
46
|
"terser-webpack-plugin": "^5.3.10",
|
|
47
47
|
"typescript": "^5.6.2",
|
|
48
|
-
"webpack": "5.99.
|
|
48
|
+
"webpack": "5.99.9",
|
|
49
49
|
"webpack-cli": "^5.1.4",
|
|
50
50
|
"webpack-dev-server": "^5.0.4"
|
|
51
51
|
},
|
package/src/composite.js
CHANGED
|
@@ -2,16 +2,46 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
+
import TagNamesCommon from './tag-names-common.js';
|
|
6
|
+
|
|
7
|
+
const FOCAL_PLANE_RESOLUTION_UNIT = {
|
|
8
|
+
INCHES: 2,
|
|
9
|
+
CENTIMETERS: 3,
|
|
10
|
+
MILLIMETERS: 4
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const UNIT_FACTORS = {
|
|
14
|
+
INCHES_TO_MM: 25.4, // 1 inch = 25.4 mm
|
|
15
|
+
CM_TO_MM: 10, // 1 cm = 10 mm
|
|
16
|
+
MM_TO_MM: 1 // Already in mm
|
|
17
|
+
};
|
|
18
|
+
|
|
5
19
|
export default {
|
|
6
20
|
get,
|
|
7
21
|
};
|
|
8
22
|
|
|
23
|
+
export {FOCAL_PLANE_RESOLUTION_UNIT};
|
|
24
|
+
|
|
9
25
|
function get(tags, expanded) {
|
|
10
26
|
const compositeTags = {};
|
|
11
27
|
let hasCompositeTags = false;
|
|
12
28
|
|
|
13
|
-
const focalLength = getTagValue(tags, 'FocalLength', expanded);
|
|
14
|
-
const
|
|
29
|
+
const focalLength = getTagValue(tags, 'exif', 'FocalLength', expanded);
|
|
30
|
+
const focalPlaneXResolution = getTagValue(tags, 'exif', 'FocalPlaneXResolution', expanded);
|
|
31
|
+
const focalPlaneYResolution = getTagValue(tags, 'exif', 'FocalPlaneYResolution', expanded);
|
|
32
|
+
const focalPlaneResolutionUnit = getTagValue(tags, 'exif', 'FocalPlaneResolutionUnit', expanded);
|
|
33
|
+
const imageWidth = getTagValue(tags, 'file', 'Image Width', expanded);
|
|
34
|
+
const imageHeight = getTagValue(tags, 'file', 'Image Height', expanded);
|
|
35
|
+
const focalLengthIn35mmFilm = getTagValue(tags, 'exif', 'FocalLengthIn35mmFilm', expanded)
|
|
36
|
+
|| getFocalLengthIn35mmFilmValue(focalPlaneXResolution, focalPlaneYResolution, focalPlaneResolutionUnit, imageWidth, imageHeight, focalLength);
|
|
37
|
+
|
|
38
|
+
if (focalLengthIn35mmFilm) {
|
|
39
|
+
compositeTags.FocalLength35efl = {
|
|
40
|
+
value: focalLengthIn35mmFilm,
|
|
41
|
+
description: TagNamesCommon.FocalLengthIn35mmFilm(focalLengthIn35mmFilm)
|
|
42
|
+
};
|
|
43
|
+
hasCompositeTags = true;
|
|
44
|
+
}
|
|
15
45
|
|
|
16
46
|
const scaleFactorTo35mmEquivalent = getScaleFactorTo35mmEquivalent(focalLength, focalLengthIn35mmFilm);
|
|
17
47
|
if (scaleFactorTo35mmEquivalent) {
|
|
@@ -32,9 +62,9 @@ function get(tags, expanded) {
|
|
|
32
62
|
return undefined;
|
|
33
63
|
}
|
|
34
64
|
|
|
35
|
-
function getTagValue(tags, tagName, expanded) {
|
|
36
|
-
if (expanded && tags
|
|
37
|
-
return tags
|
|
65
|
+
function getTagValue(tags, group, tagName, expanded) {
|
|
66
|
+
if (expanded && tags[group] && tags[group][tagName]) {
|
|
67
|
+
return tags[group][tagName].value;
|
|
38
68
|
}
|
|
39
69
|
if (!expanded && tags[tagName]) {
|
|
40
70
|
return tags[tagName].value;
|
|
@@ -42,6 +72,59 @@ function getTagValue(tags, tagName, expanded) {
|
|
|
42
72
|
return undefined;
|
|
43
73
|
}
|
|
44
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Calculates the 35mm equivalent focal length from camera sensor data.
|
|
77
|
+
*
|
|
78
|
+
* This function determines how the field of view of a camera's sensor compares to a
|
|
79
|
+
* standard 35mm film frame (36mm × 24mm). The conversion involves:
|
|
80
|
+
*
|
|
81
|
+
* 1. **Sensor dimensions**: Calculated from image pixel count and focal plane
|
|
82
|
+
* resolution (pixels per unit area)
|
|
83
|
+
* 2. **Crop factor**: The ratio between the sensor diagonal and the standard
|
|
84
|
+
* 35mm diagonal (43.27mm)
|
|
85
|
+
* 3. **Equivalent focal length**: Actual focal length multiplied by the crop factor
|
|
86
|
+
*
|
|
87
|
+
* For example, a 50mm lens on a camera with a 1.5x crop factor gives an equivalent
|
|
88
|
+
* field of view of a 75mm lens on a 35mm camera. This doesn't change the actual
|
|
89
|
+
* focal length or depth of field characteristics, only the angle of view.
|
|
90
|
+
*/
|
|
91
|
+
function getFocalLengthIn35mmFilmValue(focalPlaneXResolution, focalPlaneYResolution, focalPlaneResolutionUnit, imageWidth, imageHeight, focalLength) {
|
|
92
|
+
// Standard 35mm film diagonal is 43.27mm (calculated from 36mm x 24mm frame)
|
|
93
|
+
const DIAGONAL_35mm = 43.27;
|
|
94
|
+
|
|
95
|
+
if (focalPlaneXResolution && focalPlaneYResolution && focalPlaneResolutionUnit && imageWidth && imageHeight && focalLength) {
|
|
96
|
+
try {
|
|
97
|
+
let resolutionUnitFactor;
|
|
98
|
+
switch (focalPlaneResolutionUnit) {
|
|
99
|
+
case FOCAL_PLANE_RESOLUTION_UNIT.INCHES:
|
|
100
|
+
resolutionUnitFactor = UNIT_FACTORS.INCHES_TO_MM;
|
|
101
|
+
break;
|
|
102
|
+
case FOCAL_PLANE_RESOLUTION_UNIT.CENTIMETERS:
|
|
103
|
+
resolutionUnitFactor = UNIT_FACTORS.CM_TO_MM;
|
|
104
|
+
break;
|
|
105
|
+
case FOCAL_PLANE_RESOLUTION_UNIT.MILLIMETERS:
|
|
106
|
+
resolutionUnitFactor = UNIT_FACTORS.MM_TO_MM;
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const focalPlaneXResolutionMm = focalPlaneXResolution[0] / focalPlaneXResolution[1] * resolutionUnitFactor;
|
|
113
|
+
const focalPlaneYResolutionMm = focalPlaneYResolution[0] / focalPlaneYResolution[1] * resolutionUnitFactor;
|
|
114
|
+
|
|
115
|
+
const sensorWidthMm = imageWidth / focalPlaneXResolutionMm;
|
|
116
|
+
const sensorHeightMm = imageHeight / focalPlaneYResolutionMm;
|
|
117
|
+
|
|
118
|
+
const sensorDiagonal = Math.sqrt(sensorWidthMm ** 2 + sensorHeightMm ** 2);
|
|
119
|
+
const focalLength35mm = (focalLength[0] / focalLength[1]) * (DIAGONAL_35mm / sensorDiagonal);
|
|
120
|
+
return focalLength35mm;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
// Ignore.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
45
128
|
function getScaleFactorTo35mmEquivalent(focalLength, focalLengthIn35mmFilm) {
|
|
46
129
|
if (focalLength && focalLengthIn35mmFilm) {
|
|
47
130
|
try {
|
package/src/exif-reader.js
CHANGED
|
@@ -288,7 +288,7 @@ export function loadView(
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
if (Constants.USE_PHOTOSHOP && readTags['ImageSourceData']) {
|
|
291
|
+
if (Constants.USE_PHOTOSHOP && readTags['ImageSourceData'] && readTags['PhotoshopSettings']) {
|
|
292
292
|
const readPhotoshopTags = PhotoshopTags.read(readTags['PhotoshopSettings'].value, includeUnknown);
|
|
293
293
|
if (expanded) {
|
|
294
294
|
tags.photoshop = readPhotoshopTags;
|
package/src/tag-names-common.js
CHANGED
|
@@ -101,6 +101,8 @@ export default {
|
|
|
101
101
|
return 'inches';
|
|
102
102
|
} else if (value === 3) {
|
|
103
103
|
return 'centimeters';
|
|
104
|
+
} else if (value === 4) {
|
|
105
|
+
return 'millimeters';
|
|
104
106
|
}
|
|
105
107
|
return 'Unknown';
|
|
106
108
|
},
|
|
@@ -185,6 +187,12 @@ export default {
|
|
|
185
187
|
}
|
|
186
188
|
return 'Unknown';
|
|
187
189
|
},
|
|
190
|
+
FocalLengthIn35mmFilm(value) {
|
|
191
|
+
if (value === 0) {
|
|
192
|
+
return 'Unknown';
|
|
193
|
+
}
|
|
194
|
+
return value + ' mm';
|
|
195
|
+
},
|
|
188
196
|
SceneCaptureType(value) {
|
|
189
197
|
if (value === 0) {
|
|
190
198
|
return 'Standard';
|
|
@@ -296,12 +296,7 @@ export default {
|
|
|
296
296
|
},
|
|
297
297
|
0xa405: {
|
|
298
298
|
'name': 'FocalLengthIn35mmFilm', // Sometimes called FocalLengthIn35mmFormat.
|
|
299
|
-
'description':
|
|
300
|
-
if (value === 0) {
|
|
301
|
-
return 'Unknown';
|
|
302
|
-
}
|
|
303
|
-
return value + ' mm';
|
|
304
|
-
}
|
|
299
|
+
'description': TagNamesCommon.FocalLengthIn35mmFilm
|
|
305
300
|
},
|
|
306
301
|
0xa406: {
|
|
307
302
|
'name': 'SceneCaptureType',
|