This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
exif.js
67 lines (52 loc) · 1.67 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//const exiftool = require("exiftool-vendored").exiftool;
const ExifTool = require("exiftool-vendored").ExifTool;
let numCPUs = require("os").cpus().length;
const exiftool = new ExifTool({
maxProcs: numCPUs
});
// maxProcs: DefaultMaxProcs,
/**
* look for XMP tag and return an array of it
* @param {} filename
* @returns {modif,tags}
*/
function getFromImage(filename) {
// console.log(`getting exif for ${filename}`);
return new Promise(function (resolve, reject) {
exiftool
.read(filename)
.then(tags => {
//console.log("exif tags ",tags);
const d = tags.FileModifyDate;
const modif = new Date(d.year, d.month - 1, d.day, d.hour, d.minute, d.second, 0);
//console.log("fileModifyDate: ",d );
const lat = tags.GPSLatitude;
const lng = tags.GPSLongitude;
let pos = null;
if (lat && lng)
pos = {
lat: lat,
lng: lng
};
let faces = [];
if (Object.prototype.hasOwnProperty.call(tags, "PersonInImage"))
faces = tags.PersonInImage;
resolve({
modif: modif,
faces: faces,
pos: pos,
tags: tags
});
})
.catch(err => {
reject(err);
});
});
}
function end() {
exiftool.end();
}
module.exports = {
getFromImage: getFromImage,
end: end
};