Created
November 2, 2018 23:05
-
-
Save ahmeti/58115f1ad2d0e9ebac0e8ea8aa8ce277 to your computer and use it in GitHub Desktop.
Remove Borders (1px) on Image with NodeJS
This file contains hidden or 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 fs = require('fs') | |
, gm = require('gm').subClass({imageMagick: true}); | |
const imagesFolder = 'public/images/1/featured'; | |
function getFilePaths() { | |
return new Promise(resolve => { | |
fs.readdir(imagesFolder, (err, files) => { | |
resolve(files); | |
}); | |
}); | |
} | |
async function run() { | |
const files = await getFilePaths(); | |
for (const file of files) { | |
const contents = await imageEdit(imagesFolder + '/' + file); | |
console.log(contents); | |
} | |
} | |
function imageEdit(file) | |
{ | |
return new Promise(resolve => { | |
gm(file) | |
.size(function (err, size) { | |
if (!err) { | |
gm(file) | |
.resize(size.width + 4, size.height + 4, '^') | |
.gravity('Center') | |
.crop(size.width + 2, size.height + 2) | |
.noProfile() | |
.write(file, function (err) { | |
if (!err){ | |
resolve(file) | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment