Skip to content

Instantly share code, notes, and snippets.

@recyclerobot
Created March 18, 2014 21:12
Show Gist options
  • Save recyclerobot/9629768 to your computer and use it in GitHub Desktop.
Save recyclerobot/9629768 to your computer and use it in GitHub Desktop.
Day/Night/Morning checker
var fs = require('fs')
, gm = require('gm');
var threshold = {
"night":
{
"from": 0,
"to": 10000
},
"morning":
{
"from": 10000,
"to": 50000
},
"day":
{
"from": 50000,
"to": 500000
}
}
process.argv.forEach(function (val, index, array) {
if(index>1){
console.log('checking day or night for: ' + val);
checkDayOrNight(val);
}
});
function checkDayOrNight(pic){
gm(pic).color(function (err, c) {
if(!err){
for (var key in threshold) {
var obj = threshold[key];
if(c < obj["to"] && c > obj["from"]){
console.log(pic + "= " + key);
}
}
}else{
console.log("ERROR: "+err);
}
});
}
/*
NIGHT
------
{ Red:
{ Minimum: '0.00 (0.0000)',
Maximum: '99.00 (0.3882)',
Mean: '3.02 (0.0119)',
'Standard Deviation': '2.40 (0.0094)' },
Green:
{ Minimum: '0.00 (0.0000)',
Maximum: '73.00 (0.2863)',
Mean: '0.96 (0.0038)',
'Standard Deviation': '0.97 (0.0038)' },
Blue:
{ Minimum: '0.00 (0.0000)',
Maximum: '56.00 (0.2196)',
Mean: '1.63 (0.0064)',
'Standard Deviation': '1.66 (0.0065)' } }
MORNING
-------
{ Red:
{ Minimum: '0.00 (0.0000)',
Maximum: '230.00 (0.9020)',
Mean: '16.02 (0.0628)',
'Standard Deviation': '21.51 (0.0843)' },
Green:
{ Minimum: '0.00 (0.0000)',
Maximum: '255.00 (1.0000)',
Mean: '17.14 (0.0672)',
'Standard Deviation': '20.96 (0.0822)' },
Blue:
{ Minimum: '0.00 (0.0000)',
Maximum: '255.00 (1.0000)',
Mean: '12.09 (0.0474)',
'Standard Deviation': '20.76 (0.0814)' } }
DAY
----
{ Red:
{ Minimum: '0.00 (0.0000)',
Maximum: '255.00 (1.0000)',
Mean: '73.82 (0.2895)',
'Standard Deviation': '53.82 (0.2111)' },
Green:
{ Minimum: '0.00 (0.0000)',
Maximum: '255.00 (1.0000)',
Mean: '70.48 (0.2764)',
'Standard Deviation': '54.61 (0.2142)' },
Blue:
{ Minimum: '0.00 (0.0000)',
Maximum: '255.00 (1.0000)',
Mean: '65.77 (0.2579)',
'Standard Deviation': '53.91 (0.2114)' } }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment