Created
December 5, 2015 16:08
-
-
Save pevers/639dd96bdc8b19025b3d to your computer and use it in GitHub Desktop.
Convert files to 3-channel JPG using GM
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
'use strict' | |
var fs = require('fs') | |
, gm = require('gm'); | |
// transform all files to 3-channel JPG | |
function convert(dir, out, callback) { | |
var i = 0, data = []; | |
fs.readdir(dir, function (err, files) { | |
if (err) callback(err); | |
files.forEach(function (f) { | |
gm(dir + f).flatten().setFormat('jpg').colorspace('RGB').write(out + f, function (error) { | |
if (!error) data.push(out + f); | |
if (++i === files.length) callback(null, data); | |
}); | |
}); | |
}); | |
} | |
convert('./out/', './tmp/', function (err, result) { | |
console.log('result', result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment