Skip to content

Instantly share code, notes, and snippets.

@mildfuzz
Last active December 24, 2015 14:09
Show Gist options
  • Save mildfuzz/6810422 to your computer and use it in GitHub Desktop.
Save mildfuzz/6810422 to your computer and use it in GitHub Desktop.
exports.trimSouthEast = function(files){
/*
* Trims the bottom and right edges
*/
files.forEach(function(file, i){
var origFile = __dirname + file;
var tempFile1 = os.tmpDir() + 'image1_' +i+'.png';
var tempFile2 = os.tmpDir() + 'image2_' +i+'.png';
exec("convert "+file+" -gravity North -background white -splice 0x1 -background black -splice 0x1 -trim +repage -chop 0x1 "+tempFile1,function(){
exec("convert "+tempFile1+" -gravity West -background white -splice 1x0 -background black -splice 1x0 -trim +repage -chop 1x0 "+tempFile2,function(){
fs.readFile(tempFile2, function(newFile){
fs.writeFile(origFile, newFile);
});
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment