forked from tj/node-exif
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
39 lines (33 loc) · 945 Bytes
/
index.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
/**
* Module dependencies.
*/
var exec = require('child_process').exec;
var command = require('shelly');
/**
* Fetch EXIF data from `file` and invoke `fn(err, data)`.
*
* @param {String} file
* @param {Object} execOpts [optional] options to pass to exec() for a finer control
* @param {Function} fn
* @api public
*/
module.exports = function(file, execOpts, fn){
// rationalize options
if(typeof execOpts === 'function') {
fn = execOpts;
execOpts = {};
}
// REM : exiftool options http://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
// -json : ask JSON output
var cmd = command('exiftool -json ?', file);
exec(cmd, execOpts, function(err, str)
{
if(err) {
if(err.message === 'stdout maxBuffer exceeded.')
err = new Error('Metadata too big !'); // convert to a clearer message
return fn(err);
}
var obj = JSON.parse(str)[0]; // so easy
fn(null, obj);
});
};