A Sample Script To Get EXIF Data From Image File.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const fs = require('fs'); | |
const piexif = require('piexifjs'); | |
function getExifFromImage(imgPath) { | |
const imgData = fs.readFileSync(imgPath).toString('binary'); | |
const exifRawData = piexif.load(imgData); | |
const exifData = {}; | |
for (const exifType in exifRawData) { | |
if (exifType === 'thumbnail') { | |
continue; | |
} | |
if (!exifData.hasOwnProperty(exifType)) { | |
exifData[exifType] = {}; | |
} | |
for (const tag in exifRawData[exifType]) { | |
const tagName = piexif.Tags[exifType][tag]['name']; | |
exifData[exifType][tagName] = exifRawData[exifType][tag]; | |
} | |
} | |
return exifData; | |
} | |
async function main() { | |
const srcDirPath = 'SOURCE_DIRECTORY_PATH'; | |
const srcFileList = fs.readdirSync(srcDirPath); | |
for (const srcFileName of srcFileList) { | |
if (!srcFileName.endsWith('.JPG')) { | |
continue; | |
} | |
console.log('Processing ', srcFileName, '...'); | |
try { | |
const exifData = getExifFromImage(path.join(srcDirPath, srcFileName)); | |
for (const exifType in exifData) { | |
console.log(exifType, '----------'); | |
for (const tagName in exifData[exifType]) { | |
console.log(tagName + ': ' + exifData[exifType][tagName]); | |
} | |
console.log(); | |
} | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment