Skip to content

Instantly share code, notes, and snippets.

@pevers
Created December 5, 2015 16:08
Show Gist options
  • Save pevers/639dd96bdc8b19025b3d to your computer and use it in GitHub Desktop.
Save pevers/639dd96bdc8b19025b3d to your computer and use it in GitHub Desktop.
Convert files to 3-channel JPG using GM
'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