exif
Advanced tools
Comparing version 0.3.0 to 0.3.3
@@ -28,2 +28,3 @@ var fs = require('fs'), | ||
this.isBigEndian; | ||
this.makernoteOffset; | ||
@@ -38,3 +39,3 @@ this.exifData = { | ||
}; | ||
if (!options.image) { | ||
@@ -159,3 +160,3 @@ throw new Error('You have to provide an image, it is pretty hard to extract Exif data from nothing...'); | ||
var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.exif); | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.image[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.image[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -176,3 +177,3 @@ | ||
var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.exif); | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.thumbnail[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.thumbnail[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -187,3 +188,3 @@ } | ||
ifdOffset = tiffOffset + this.exifData.image[ExifImage.TAGS.exif[0x8769]].value; | ||
ifdOffset = tiffOffset + this.exifData.image[ExifImage.TAGS.exif[0x8769]]; | ||
numberOfEntries = data.getShort(ifdOffset, this.isBigEndian); | ||
@@ -195,3 +196,3 @@ | ||
var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.exif); | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.exif[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.exif[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -207,3 +208,3 @@ | ||
ifdOffset = tiffOffset + this.exifData.image[ExifImage.TAGS.exif[0x8825]].value; | ||
ifdOffset = tiffOffset + this.exifData.image[ExifImage.TAGS.exif[0x8825]]; | ||
numberOfEntries = data.getShort(ifdOffset, this.isBigEndian); | ||
@@ -215,3 +216,3 @@ | ||
var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.gps); | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.gps[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.gps[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -227,10 +228,10 @@ | ||
ifdOffset = tiffOffset + this.exifData.exif[ExifImage.TAGS.exif[0xA005]].value; | ||
ifdOffset = tiffOffset + this.exifData.exif[ExifImage.TAGS.exif[0xA005]]; | ||
numberOfEntries = data.getShort(ifdOffset, this.isBigEndian); | ||
// Each IFD entry consists of 12 bytes which we loop through and extract | ||
// the data from | ||
for (var i = 0; i < numberOfEntries; i++) { | ||
var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian); | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.interoperability[exifEntry.tagName] = exifEntry; | ||
var exifEntry = self.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, ExifImage.TAGS.exif); | ||
if (exifEntry && exifEntry.tagName !== null) this.exifData.interoperability[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -248,9 +249,9 @@ | ||
// Check the header to see what kind of Makernote we are dealing with | ||
if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].value.getString(0, 7) === "OLYMP\x00\x01" || this.exifData.exif[ExifImage.TAGS.exif[0x927C]].value.getString(0, 7) === "OLYMP\x00\x02") { | ||
if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].getString(0, 7) === "OLYMP\x00\x01" || this.exifData.exif[ExifImage.TAGS.exif[0x927C]].getString(0, 7) === "OLYMP\x00\x02") { | ||
this.extractMakernotes = require('./makernotes/olympus').extractMakernotes; | ||
} else if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].value.getString(0, 7) === "AGFA \x00\x01") { | ||
} else if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].getString(0, 7) === "AGFA \x00\x01") { | ||
this.extractMakernotes = require('./makernotes/agfa').extractMakernotes; | ||
} else if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].value.getString(0, 8) === "EPSON\x00\x01\x00") { | ||
} else if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].getString(0, 8) === "EPSON\x00\x01\x00") { | ||
this.extractMakernotes = require('./makernotes/epson').extractMakernotes; | ||
} else if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].value.getString(0, 8) === "FUJIFILM") { | ||
} else if (this.exifData.exif[ExifImage.TAGS.exif[0x927C]].getString(0, 8) === "FUJIFILM") { | ||
this.extractMakernotes = require('./makernotes/fujifilm').extractMakernotes; | ||
@@ -261,6 +262,6 @@ } else { | ||
// solution but should do for now | ||
this.exifData.makernote.push({ error: 'Unable to extract Makernote information as it is in an unrecognized format.' }); | ||
this.exifData.makernote['error'] = 'Unable to extract Makernote information as it is in an unsupported or unrecognized format.'; | ||
} | ||
this.exifData.makernote = this.extractMakernotes(data, this.exifData.exif[ExifImage.TAGS.exif[0x927C]].valueOffset, tiffOffset); | ||
this.exifData.makernote = this.extractMakernotes(data, self.makernoteOffset, tiffOffset); | ||
@@ -275,2 +276,4 @@ } | ||
var self = this; | ||
var entry = { | ||
@@ -353,3 +356,6 @@ tag : data.slice(entryOffset, entryOffset + 2), | ||
} | ||
// If this is the Makernote tag save its offset for later use | ||
if (entry.tagName === "MakerNote") self.makernoteOffset = entry.valueOffset; | ||
// If the value array has only one element we don't need an array | ||
@@ -356,0 +362,0 @@ if (entry.value.length == 1) entry.value = entry.value[0]; |
@@ -6,3 +6,3 @@ /** | ||
var makernoteData = []; | ||
var makernoteData = {}; | ||
@@ -141,3 +141,3 @@ // List of vendor specific Makernote tags found on | ||
var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, tags); | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -144,0 +144,0 @@ |
@@ -6,3 +6,3 @@ /** | ||
var makernoteData = []; | ||
var makernoteData = {}; | ||
@@ -141,3 +141,3 @@ // List of vendor specific Makernote tags found on | ||
var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, tags); | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -144,0 +144,0 @@ |
@@ -9,3 +9,3 @@ /** | ||
var makernoteData = []; | ||
var makernoteData = {}; | ||
@@ -71,3 +71,3 @@ // List of vendor specific Makernote tags found on | ||
var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), makernoteOffset, false, tags); | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -74,0 +74,0 @@ |
@@ -6,3 +6,3 @@ /** | ||
var makernoteData = []; | ||
var makernoteData = {}; | ||
@@ -141,3 +141,3 @@ // List of vendor specific Makernote tags found on | ||
var exifEntry = this.extractExifEntry(data, (ifdOffset + 2 + (i * 12)), tiffOffset, this.isBigEndian, tags); | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry; | ||
if (exifEntry && exifEntry.tagName !== null) makernoteData[exifEntry.tagName] = exifEntry.value; | ||
} | ||
@@ -144,0 +144,0 @@ |
{ | ||
"name" : "exif", | ||
"version" : "0.3.0", | ||
"version" : "0.3.3", | ||
"description" : "A node.js library to extract Exif metadata from images.", | ||
@@ -5,0 +5,0 @@ "author" : "Daniel Leinich <leinich@gmx.net>", |
143
README.md
node-exif | ||
========= | ||
With _node-exif_ you can extract Exif metadata from images (JPEG). Exif is a | ||
format used, for example, by digital cameras and scanners to save additional | ||
information about an image in the image file. This information can be the | ||
camera model, resolution, where the image was taken (GPS) or when it was taken. | ||
With _node-exif_ you can extract Exif metadata from images (JPEG). Exif is a format used, for example, by digital cameras and scanners to save additional information about an image in the image file. This information can be the camera model, resolution, where the image was taken (GPS) or when it was taken. | ||
@@ -24,41 +21,117 @@ Installation | ||
Easy. Just require _node-exif_ and throw an image at it. If _node-exif_ is able to | ||
extract data from the image it does so and returns an object with all the | ||
information found, if an error occurs you will receive an error message. To | ||
prove that it really is easy please see the following example. | ||
Easy. Just require _node-exif_ and throw an image at it. If _node-exif_ is able to extract data from the image it does so and returns an object with all the information found, if an error occurs you will receive an error message. To prove that it really is easy please see the following example. | ||
var ExifImage = require('exif').ExifImage; | ||
```javascript | ||
var ExifImage = require('exif').ExifImage; | ||
try { | ||
new ExifImage({ image : 'myImage.jpg' }, function (error, image) { | ||
if (error) | ||
console.log('Error: '+error.message); | ||
else | ||
console.log(image); // Do something with your data! | ||
}); | ||
} catch (error) { | ||
console.log('Error: ' + error); | ||
} | ||
try { | ||
new ExifImage({ image : 'myImage.jpg' }, function (error, exifData) { | ||
if (error) | ||
console.log('Error: '+error.message); | ||
else | ||
console.log(exifData); // Do something with your data! | ||
}); | ||
} catch (error) { | ||
console.log('Error: ' + error.message); | ||
} | ||
``` | ||
Instead of providing a filename of an image in your filesystem you can also | ||
pass a Buffer to ExifImage. | ||
Instead of providing a filename of an image in your filesystem you can also pass a Buffer to ExifImage. | ||
The data returned is an object with a couple of arrays, each of the arrays | ||
consists of the metadata extracted from the respective section. Please refer | ||
to ExifImage.js for a list of available tags and their meaning, there is a lot | ||
of them. This is subject to change, though, as it's not really self explanatory | ||
right now. | ||
The data returned (`exifData` in the example above) is an object containing objects for each type of available Exif metadata: | ||
* `image` for image information data (IFD0) | ||
* `thumbnail` for information regarding a possibly embedded thumbnail (IFD1) | ||
* `exif` for Exif-specific attribute information (Exif IFD) | ||
* `gps` for GPS information (GPS IFD) | ||
* `interoperability` for interoperability information (Interoperability IFD) | ||
* `makernote` for vendor specific Exif information (Makernotes) | ||
The ouput for an [example image](http://www.exif.org/samples/fujifilm-finepix40i.jpg) might thus look like this: | ||
``` | ||
{ | ||
image: { | ||
Make: 'FUJIFILM', | ||
Model: 'FinePix40i', | ||
Orientation: 1, | ||
XResolution: 72, | ||
YResolution: 72, | ||
ResolutionUnit: 2, | ||
Software: 'Digital Camera FinePix40i Ver1.39', | ||
ModifyDate: '2000:08:04 18:22:57', | ||
YCbCrPositioning: 2, | ||
Copyright: ' ', | ||
ExifOffset: 250 | ||
}, | ||
thumbnail: { | ||
Compression: 6, | ||
Orientation: 1, | ||
XResolution: 72, | ||
YResolution: 72, | ||
ResolutionUnit: 2, | ||
ThumbnailOffset: 1074, | ||
ThumbnailLength: 8691, | ||
YCbCrPositioning: 2 | ||
}, | ||
exif: { | ||
FNumber: 2.8, | ||
ExposureProgram: 2, | ||
ISO: 200, | ||
ExifVersion: <Buffer 30 32 31 30>, | ||
DateTimeOriginal: '2000:08:04 18:22:57', | ||
CreateDate: '2000:08:04 18:22:57', | ||
ComponentsConfiguration: <Buffer 01 02 03 00>, | ||
CompressedBitsPerPixel: 1.5, | ||
ShutterSpeedValue: 5.5, | ||
ApertureValue: 3, | ||
BrightnessValue: 0.26, | ||
ExposureCompensation: 0, | ||
MaxApertureValue: 3, | ||
MeteringMode: 5, | ||
Flash: 1, | ||
FocalLength: 8.7, | ||
MakerNote: <Buffer 46 55 4a 49 46 49 4c 4d 0c 00 00 00 0f 00 00 00 07 00 04 00 00 00 30 31 33 30 00 10 02 00 08 00 00 00 c6 00 00 00 01 10 03 00 01 00 00 00 03 00 00 00 02 ...>, | ||
FlashpixVersion: <Buffer 30 31 30 30>, | ||
ColorSpace: 1, | ||
ExifImageWidth: 2400, | ||
ExifImageHeight: 1800, | ||
InteropOffset: 926, | ||
FocalPlaneXResolution: 2381, | ||
FocalPlaneYResolution: 2381, | ||
FocalPlaneResolutionUnit: 3, | ||
SensingMethod: 2, | ||
FileSource: <Buffer 03>, | ||
SceneType: <Buffer 01> | ||
}, | ||
gps: {}, | ||
interoperability: { | ||
InteropIndex: 'R98', | ||
InteropVersion: <Buffer 30 31 30 30> | ||
}, | ||
makernote: { | ||
Version: <Buffer 30 31 33 30>, | ||
Quality: 'NORMAL ', | ||
Sharpness: 3, | ||
WhiteBalance: 0, | ||
FujiFlashMode: 1, | ||
FlashExposureComp: 0, | ||
Macro: 0, | ||
FocusMode: 0, | ||
SlowSync: 0, | ||
AutoBracketing: 0, | ||
BlurWarning: 0, | ||
FocusWarning: 0, | ||
ExposureWarning: 0 | ||
} | ||
} | ||
``` | ||
For more information about the Exif standard please refer to the specification found on [http://www.exif.org](http://www.exif.org). A comprehensive list of available Exif attributes and their meaning can be found on [http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/](http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/). | ||
ToDo / Ideas | ||
------------ | ||
* Testing, testing, testing | ||
* Performance improvements | ||
* Better access to extracted data | ||
* Fetch remote files and extract metadata from them | ||
* Extract makernote information | ||
* Enhance interoperability information | ||
* Add string representations for flags | ||
* You name it | ||
There are a lot of things still to be done and to be made better. If you have any special requests please open an issue with a feature request. | ||
License | ||
@@ -65,0 +138,0 @@ ------- |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
53230
1336
139
0