exifreader
Advanced tools
Comparing version 4.5.1 to 4.6.0
{ | ||
"name": "exifreader", | ||
"version": "4.5.1", | ||
"version": "4.6.0", | ||
"description": "Library that parses Exif metadata in images.", | ||
@@ -5,0 +5,0 @@ "author": "Mattias Wallander <mattias@wallander.eu>", |
@@ -88,5 +88,5 @@ ExifReader | ||
Type definitions for TypeScript are included in the package. If you're missing | ||
any definitions for tags or something else, a pull-request would be very much | ||
welcome since I'm not using TypeScript myself. | ||
Type definitions for TypeScript are included in the package. I'm not maintaining | ||
those so if you're missing any definitions for tags or something else, a | ||
pull-request would be very welcome. | ||
@@ -93,0 +93,0 @@ Usage |
/** | ||
* ExifReader | ||
* http://github.com/mattiasw/exifreader | ||
* Copyright (C) 2011-2021 Mattias Wallander <mattias@wallander.eu> | ||
* Copyright (C) 2011-2022 Mattias Wallander <mattias@wallander.eu> | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
@@ -6,0 +6,0 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this |
@@ -96,11 +96,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
'name': 'XResolution', | ||
'description': (value) => { | ||
return '' + Math.round(value[0] / value[1]); | ||
} | ||
'description': TagNamesCommon.XResolution | ||
}, | ||
0x011b: { | ||
'name': 'YResolution', | ||
'description': (value) => { | ||
return '' + Math.round(value[0] / value[1]); | ||
} | ||
'description': TagNamesCommon.YResolution | ||
}, | ||
@@ -133,11 +129,3 @@ 0x011c: 'PlanarConfiguration', | ||
name: 'ResolutionUnit', | ||
description: (value) => { | ||
if (value === 2) { | ||
return 'inches'; | ||
} | ||
if (value === 3) { | ||
return 'centimeters'; | ||
} | ||
return 'Unknown'; | ||
} | ||
description: TagNamesCommon.ResolutionUnit | ||
}, | ||
@@ -144,0 +132,0 @@ 0x0129: 'PageNumber', |
@@ -6,4 +6,101 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
export default { | ||
'LightSource': (value) => { | ||
ApertureValue: (value) => Math.pow(Math.sqrt(2), value[0] / value[1]).toFixed(2), | ||
ColorSpace(value) { | ||
if (value === 1) { | ||
return 'sRGB'; | ||
} else if (value === 0xffff) { | ||
return 'Uncalibrated'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
ComponentsConfiguration(value) { | ||
return value.map((character) => { | ||
if (character === 0x31) { | ||
return 'Y'; | ||
} else if (character === 0x32) { | ||
return 'Cb'; | ||
} else if (character === 0x33) { | ||
return 'Cr'; | ||
} else if (character === 0x34) { | ||
return 'R'; | ||
} else if (character === 0x35) { | ||
return 'G'; | ||
} else if (character === 0x36) { | ||
return 'B'; | ||
} | ||
}).join(''); | ||
}, | ||
Contrast(value) { | ||
if (value === 0) { | ||
return 'Normal'; | ||
} else if (value === 1) { | ||
return 'Soft'; | ||
} else if (value === 2) { | ||
return 'Hard'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
CustomRendered(value) { | ||
if (value === 0) { | ||
return 'Normal process'; | ||
} else if (value === 1) { | ||
return 'Custom process'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
ExposureMode(value) { | ||
if (value === 0) { | ||
return 'Auto exposure'; | ||
} else if (value === 1) { | ||
return 'Manual exposure'; | ||
} else if (value === 2) { | ||
return 'Auto bracket'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
ExposureProgram(value) { | ||
if (value === 0) { | ||
return 'Undefined'; | ||
} else if (value === 1) { | ||
return 'Manual'; | ||
} else if (value === 2) { | ||
return 'Normal program'; | ||
} else if (value === 3) { | ||
return 'Aperture priority'; | ||
} else if (value === 4) { | ||
return 'Shutter priority'; | ||
} else if (value === 5) { | ||
return 'Creative program'; | ||
} else if (value === 6) { | ||
return 'Action program'; | ||
} else if (value === 7) { | ||
return 'Portrait mode'; | ||
} else if (value === 8) { | ||
return 'Landscape mode'; | ||
} else if (value === 9) { | ||
return 'Bulb'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
ExposureTime(value) { | ||
if (value[0] >= value[1]) { | ||
return `${Math.round(value[0] / value[1])}`; | ||
} | ||
if (value[0] !== 0) { | ||
return `1/${Math.round(value[1] / value[0])}`; | ||
} | ||
return `0/${value[1]}`; | ||
}, | ||
FNumber: (value) => `f/${value[0] / value[1]}`, | ||
FocalLength: (value) => (value[0] / value[1]) + ' mm', | ||
FocalPlaneResolutionUnit(value) { | ||
if (value === 2) { | ||
return 'inches'; | ||
} else if (value === 3) { | ||
return 'centimeters'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
LightSource: (value) => { | ||
if (value === 1) { | ||
return 'Daylight'; | ||
@@ -50,3 +147,79 @@ } else if (value === 2) { | ||
return 'Unknown'; | ||
} | ||
}, | ||
MeteringMode(value) { | ||
if (value === 1) { | ||
return 'Average'; | ||
} else if (value === 2) { | ||
return 'CenterWeightedAverage'; | ||
} else if (value === 3) { | ||
return 'Spot'; | ||
} else if (value === 4) { | ||
return 'MultiSpot'; | ||
} else if (value === 5) { | ||
return 'Pattern'; | ||
} else if (value === 6) { | ||
return 'Partial'; | ||
} else if (value === 255) { | ||
return 'Other'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
ResolutionUnit(value) { | ||
if (value === 2) { | ||
return 'inches'; | ||
} | ||
if (value === 3) { | ||
return 'centimeters'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
Saturation(value) { | ||
if (value === 0) { | ||
return 'Normal'; | ||
} else if (value === 1) { | ||
return 'Low saturation'; | ||
} else if (value === 2) { | ||
return 'High saturation'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
SceneCaptureType(value) { | ||
if (value === 0) { | ||
return 'Standard'; | ||
} else if (value === 1) { | ||
return 'Landscape'; | ||
} else if (value === 2) { | ||
return 'Portrait'; | ||
} else if (value === 3) { | ||
return 'Night scene'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
Sharpness(value) { | ||
if (value === 0) { | ||
return 'Normal'; | ||
} else if (value === 1) { | ||
return 'Soft'; | ||
} else if (value === 2) { | ||
return 'Hard'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
ShutterSpeedValue(value) { | ||
const denominator = Math.pow(2, value[0] / value[1]); | ||
if (denominator <= 1) { | ||
return `${Math.round(1 / denominator)}`; | ||
} | ||
return `1/${Math.round(denominator)}`; | ||
}, | ||
WhiteBalance(value) { | ||
if (value === 0) { | ||
return 'Auto white balance'; | ||
} else if (value === 1) { | ||
return 'Manual white balance'; | ||
} | ||
return 'Unknown'; | ||
}, | ||
XResolution: (value) => '' + Math.round(value[0] / value[1]), | ||
YResolution: (value) => '' + Math.round(value[0] / value[1]) | ||
}; |
@@ -11,42 +11,11 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
'name': 'ExposureTime', | ||
'description': (value) => { | ||
if (value[0] >= value[1]) { | ||
return `${Math.round(value[0] / value[1])}`; | ||
} | ||
if (value[0] !== 0) { | ||
return `1/${Math.round(value[1] / value[0])}`; | ||
} | ||
return `0/${value[1]}`; | ||
} | ||
'description': TagNamesCommon.ExposureTime | ||
}, | ||
0x829d: { | ||
'name': 'FNumber', | ||
'description': (value) => `f/${value[0] / value[1]}` | ||
'description': TagNamesCommon.FNumber | ||
}, | ||
0x8822: { | ||
'name': 'ExposureProgram', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Undefined'; | ||
} else if (value === 1) { | ||
return 'Manual'; | ||
} else if (value === 2) { | ||
return 'Normal program'; | ||
} else if (value === 3) { | ||
return 'Aperture priority'; | ||
} else if (value === 4) { | ||
return 'Shutter priority'; | ||
} else if (value === 5) { | ||
return 'Creative program'; | ||
} else if (value === 6) { | ||
return 'Action program'; | ||
} else if (value === 7) { | ||
return 'Portrait mode'; | ||
} else if (value === 8) { | ||
return 'Landscape mode'; | ||
} else if (value === 9) { | ||
return 'Bulb'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.ExposureProgram | ||
}, | ||
@@ -90,19 +59,3 @@ 0x8824: 'SpectralSensitivity', | ||
'name': 'ComponentsConfiguration', | ||
'description': (value) => { | ||
return value.map((character) => { | ||
if (character === 0x31) { | ||
return 'Y'; | ||
} else if (character === 0x32) { | ||
return 'Cb'; | ||
} else if (character === 0x33) { | ||
return 'Cr'; | ||
} else if (character === 0x34) { | ||
return 'R'; | ||
} else if (character === 0x35) { | ||
return 'G'; | ||
} else if (character === 0x36) { | ||
return 'B'; | ||
} | ||
}).join(''); | ||
} | ||
'description': TagNamesCommon.ComponentsConfiguration | ||
}, | ||
@@ -112,15 +65,7 @@ 0x9102: 'CompressedBitsPerPixel', | ||
'name': 'ShutterSpeedValue', | ||
'description': (value) => { | ||
const denominator = Math.pow(2, value[0] / value[1]); | ||
if (denominator <= 1) { | ||
return `${Math.round(1 / denominator)}`; | ||
} | ||
return `1/${Math.round(denominator)}`; | ||
} | ||
'description': TagNamesCommon.ShutterSpeedValue | ||
}, | ||
0x9202: { | ||
'name': 'ApertureValue', | ||
'description': (value) => { | ||
return Math.pow(Math.sqrt(2), value[0] / value[1]).toFixed(2); | ||
} | ||
'description': TagNamesCommon.ApertureValue | ||
}, | ||
@@ -141,24 +86,7 @@ 0x9203: 'BrightnessValue', | ||
'name': 'MeteringMode', | ||
'description': (value) => { | ||
if (value === 1) { | ||
return 'Average'; | ||
} else if (value === 2) { | ||
return 'CenterWeightedAverage'; | ||
} else if (value === 3) { | ||
return 'Spot'; | ||
} else if (value === 4) { | ||
return 'MultiSpot'; | ||
} else if (value === 5) { | ||
return 'Pattern'; | ||
} else if (value === 6) { | ||
return 'Partial'; | ||
} else if (value === 255) { | ||
return 'Other'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.MeteringMode | ||
}, | ||
0x9208: { | ||
'name': 'LightSource', | ||
description: TagNamesCommon['LightSource'] | ||
description: TagNamesCommon.LightSource | ||
}, | ||
@@ -218,3 +146,3 @@ 0x9209: { | ||
'name': 'FocalLength', | ||
'description': (value) => (value[0] / value[1]) + ' mm' | ||
'description': TagNamesCommon.FocalLength | ||
}, | ||
@@ -287,10 +215,3 @@ 0x9211: 'ImageNumber', | ||
'name': 'ColorSpace', | ||
'description': (value) => { | ||
if (value === 1) { | ||
return 'sRGB'; | ||
} else if (value === 0xffff) { | ||
return 'Uncalibrated'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.ColorSpace | ||
}, | ||
@@ -310,10 +231,3 @@ 0xa002: 'PixelXDimension', | ||
'name': 'FocalPlaneResolutionUnit', | ||
'description': (value) => { | ||
if (value === 2) { | ||
return 'inches'; | ||
} else if (value === 3) { | ||
return 'centimeters'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.FocalPlaneResolutionUnit | ||
}, | ||
@@ -370,34 +284,11 @@ 0xa214: { | ||
'name': 'CustomRendered', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Normal process'; | ||
} else if (value === 1) { | ||
return 'Custom process'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.CustomRendered | ||
}, | ||
0xa402: { | ||
'name': 'ExposureMode', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Auto exposure'; | ||
} else if (value === 1) { | ||
return 'Manual exposure'; | ||
} else if (value === 2) { | ||
return 'Auto bracket'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.ExposureMode | ||
}, | ||
0xa403: { | ||
'name': 'WhiteBalance', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Auto white balance'; | ||
} else if (value === 1) { | ||
return 'Manual white balance'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.WhiteBalance | ||
}, | ||
@@ -424,14 +315,3 @@ 0xa404: { | ||
'name': 'SceneCaptureType', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Standard'; | ||
} else if (value === 1) { | ||
return 'Landscape'; | ||
} else if (value === 2) { | ||
return 'Portrait'; | ||
} else if (value === 3) { | ||
return 'Night scene'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.SceneCaptureType | ||
}, | ||
@@ -457,38 +337,11 @@ 0xa407: { | ||
'name': 'Contrast', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Normal'; | ||
} else if (value === 1) { | ||
return 'Soft'; | ||
} else if (value === 2) { | ||
return 'Hard'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.Contrast | ||
}, | ||
0xa409: { | ||
'name': 'Saturation', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Normal'; | ||
} else if (value === 1) { | ||
return 'Low saturation'; | ||
} else if (value === 2) { | ||
return 'High saturation'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.Saturation | ||
}, | ||
0xa40a: { | ||
'name': 'Sharpness', | ||
'description': (value) => { | ||
if (value === 0) { | ||
return 'Normal'; | ||
} else if (value === 1) { | ||
return 'Soft'; | ||
} else if (value === 2) { | ||
return 'Hard'; | ||
} | ||
return 'Unknown'; | ||
} | ||
'description': TagNamesCommon.Sharpness | ||
}, | ||
@@ -495,0 +348,0 @@ 0xa40b: { |
@@ -5,2 +5,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
import TagNamesCommon from './tag-names-common.js'; | ||
export default { | ||
@@ -34,6 +36,55 @@ 'tiff:Orientation'(value) { | ||
}, | ||
'tiff:ResolutionUnit': (value) => TagNamesCommon.ResolutionUnit(parseInt(value, 10)), | ||
'tiff:XResolution': (value) => fraction(TagNamesCommon.XResolution, value), | ||
'tiff:YResolution': (value) => fraction(TagNamesCommon.YResolution, value), | ||
'exif:ApertureValue': (value) => fraction(TagNamesCommon.ApertureValue, value), | ||
'exif:GPSLatitude': calculateGPSValue, | ||
'exif:GPSLongitude': calculateGPSValue | ||
'exif:GPSLongitude': calculateGPSValue, | ||
'exif:FNumber': (value) => fraction(TagNamesCommon.FNumber, value), | ||
'exif:FocalLength': (value) => fraction(TagNamesCommon.FocalLength, value), | ||
'exif:FocalPlaneResolutionUnit': (value) => TagNamesCommon.FocalPlaneResolutionUnit(parseInt(value, 10)), | ||
'exif:ColorSpace': (value) => TagNamesCommon.ColorSpace(parseNumber(value)), | ||
'exif:ComponentsConfiguration'(value, description) { | ||
if (/^\d, \d, \d, \d$/.test(description)) { | ||
const numbers = description.split(', ').map((number) => number.charCodeAt(0)); | ||
return TagNamesCommon.ComponentsConfiguration(numbers); | ||
} | ||
return description; | ||
}, | ||
'exif:Contrast': (value) => TagNamesCommon.Contrast(parseInt(value, 10)), | ||
'exif:CustomRendered': (value) => TagNamesCommon.CustomRendered(parseInt(value, 10)), | ||
'exif:ExposureMode': (value) => TagNamesCommon.ExposureMode(parseInt(value, 10)), | ||
'exif:ExposureProgram': (value) => TagNamesCommon.ExposureProgram(parseInt(value, 10)), | ||
'exif:ExposureTime'(value) { | ||
if (isFraction(value)) { | ||
return TagNamesCommon.ExposureTime(value.split('/').map((number) => parseInt(number, 10))); | ||
} | ||
return value; | ||
}, | ||
'exif:MeteringMode': (value) => TagNamesCommon.MeteringMode(parseInt(value, 10)), | ||
'exif:Saturation': (value) => TagNamesCommon.Saturation(parseInt(value, 10)), | ||
'exif:SceneCaptureType': (value) => TagNamesCommon.SceneCaptureType(parseInt(value, 10)), | ||
'exif:Sharpness': (value) => TagNamesCommon.Sharpness(parseInt(value, 10)), | ||
'exif:ShutterSpeedValue': (value) => fraction(TagNamesCommon.ShutterSpeedValue, value), | ||
'exif:WhiteBalance': (value) => TagNamesCommon.WhiteBalance(parseInt(value, 10)) | ||
}; | ||
function fraction(func, value) { | ||
if (isFraction(value)) { | ||
return func(value.split('/')); | ||
} | ||
return value; | ||
} | ||
function parseNumber(value) { | ||
if (value.substring(0, 2) === '0x') { | ||
return parseInt(value.substring(2), 16); | ||
} | ||
return parseInt(value, 10); | ||
} | ||
function isFraction(value) { | ||
return /^-?\d+\/-?\d+$/.test(value); | ||
} | ||
function calculateGPSValue(value) { | ||
@@ -40,0 +91,0 @@ const [degreesString, minutesString] = value.split(','); |
@@ -232,3 +232,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
if (Array.isArray(value)) { | ||
return getDescriptionOfArray(value); | ||
const arrayDescription = getDescriptionOfArray(value); | ||
if ((name) && (typeof XmpTagNames[name] === 'function')) { | ||
return XmpTagNames[name](value, arrayDescription); | ||
} | ||
return arrayDescription; | ||
} | ||
@@ -235,0 +239,0 @@ if (typeof value === 'object') { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
539331
5588