forked from mattiasw/ExifReader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exif.js
41 lines (32 loc) · 1.01 KB
/
exif.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const path = require('path');
const fs = require('fs');
global.DataView = global.DataView || require('jdataview');
global.DOMParser = global.DOMParser || require('xmldom').DOMParser;
const ExifReader = require('../../dist/exif-reader');
if (process.argv.length < 3) {
console.log(`Usage: node ${path.basename(__filename)} <filename>`);
process.exit();
}
const filePath = process.argv[2];
fs.readFile(filePath, function (error, data) {
if (error) {
console.error('Error reading file.');
process.exit(1);
}
try {
const tags = ExifReader.load(data.buffer);
// The MakerNote tag can be really large. Remove it to lower memory
// usage if you're parsing a lot of files and saving the tags.
delete tags['MakerNote'];
listTags(tags);
} catch (error) {
console.error(error);
process.exit(1);
}
});
function listTags(tags) {
for (const name in tags) {
console.log(`${name}: ${tags[name].description}`);
}
}