Created
January 21, 2019 15:35
-
-
Save pirosuke/e536da3b89797c5f1d801cff5d3efa3b to your computer and use it in GitHub Desktop.
A Sample Script To Remove 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 removeExifFromImage(srcImgPath, destImgPath) { | |
const imgData = fs.readFileSync(srcImgPath).toString('binary'); | |
const newImgData = piexif.remove(imgData); | |
fs.writeFileSync(destImgPath, newImgData, 'binary'); | |
} | |
async function main() { | |
const srcDirPath = 'SOURCE_DIRECTORY_PATH'; | |
const destDirPath = 'DEST_DIRECTORY_PATH'; | |
const srcFileList = fs.readdirSync(srcDirPath); | |
for (const srcFileName of srcFileList) { | |
if (!srcFileName.endsWith('.JPG')) { | |
continue; | |
} | |
console.log('Processing ', srcFileName, '...'); | |
try { | |
removeExifFromImage(path.join(srcDirPath, srcFileName), path.join(destDirPath, srcFileName)); | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment