Gangmax Blog

Node.js Exif Library: piexifjs

piexifjs“ is a node.js npm library which can be used to read and write Exif data in image files.

  • Create a npm project
1
2
3
4
npm init test-project
cd test-project
npm install piexifjs
node
  • Sample code in “node” console
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const piexif = require('piexifjs');
const fs = require("fs");
var jpeg = fs.readFileSync('/Users/auser/Downloads/IMG_1302.jpg');
var data = jpeg.toString("binary");
var exifObj = piexif.load(data);

for (var ifd in exifObj) {
if (ifd == "thumbnail") {
continue;
}
console.log("-" + ifd);
for (var tag in exifObj[ifd]) {
console.log(" " + piexif.TAGS[ifd][tag]["name"] + ":" + exifObj[ifd][tag]);
}
}

From here and here.

Comments