/
parse_exif.js
43 lines (42 loc) · 1.53 KB
/
parse_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
42
43
// command-line-graphics by Jon Keegan
// this is some sample code created for my NICAR 2016 talk "Command Line Graphics"
// Twitter: @jonkeegan
// Github: https://github.com/jonkeegan
// Repo: https://github.com/jonkeegan/command-line-graphics
var ExifImage = require('exif').ExifImage;
var fs = require('fs');
// define the directory full of images we want to examine...
var directory = "samples/";
var all_data = [];
// Loop through all the files in the directory
fs.readdir(directory, function(err, files) {
if (err) {
console.error("Could not list the directory.", err);
process.exit(1);
}
var fileCount = files.length;
files.forEach(function(file, index) {
if (file != '.DS_Store' && file != '..' && file != '.') { // skip these files...
try {
new ExifImage({
image: directory + file
}, function(error, exifData) {
if (error)
console.log();
else
var this_metadata = {
"filename": file,
"metadata": exifData
};
all_data.push(this_metadata);
if (index == fileCount - 1) {
// console.log("index: "+index)
console.log(JSON.stringify(all_data));
}
});
} catch (error) {
console.log('Error: ' + error.message);
}
}
});
});