Last active
November 14, 2019 04:00
-
-
Save AdamTReineke/a387c1eeb3e3d0063e6df6a814669048 to your computer and use it in GitHub Desktop.
Sorting my wedding photos into B&W vs Color folders
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
var Jimp = require('jimp'); | |
var fs = require('fs'); | |
function isGrayFn(img, idx) { | |
return img.bitmap.data[idx] == img.bitmap.data[idx + 1] | |
&& img.bitmap.data[idx] == img.bitmap.data[idx + 2]; | |
} | |
fs.readdir("D:\\HQWeddingPhotos", (err, files) => { | |
const process = (path) => { | |
path = "D:\\HQWeddingPhotos\\" + path; | |
Jimp.read(path, (err, img) => { | |
if(err) { | |
console.log(`REM Error: ${path}`); | |
} | |
var isGray = true; | |
for (var i = 0; i < 100 && isGray === true; i++) { | |
isGray = isGray && isGrayFn(img, img.getPixelIndex(0,i)); | |
} | |
if(isGray) { | |
console.log("MOVE " + path + " " + path.replace("HQWeddingPhotos", "HQWeddingPhotos\\BW")); | |
} | |
else { | |
console.log("MOVE " + path + " " + path.replace("HQWeddingPhotos", "HQWeddingPhotos\\Color")); | |
} | |
}); | |
}; | |
for (var f = 0; f < files.length; f++) { | |
process(files[f]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment