parent
9bfcbb3340
commit
52eaa0caea
1 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
||||
const fs = require('fs'); |
||||
const path = require('path'); |
||||
const jimp = require('jimp') |
||||
|
||||
|
||||
module.exports = function (image){ |
||||
return new Promise ((resolve, reject)=>{ |
||||
let imageAddress = path.join(__dirname + "/../public/images/" + image) |
||||
let imageNameWithOutExtn = image.slice(0 , image.indexOf('.') ) |
||||
jimp.read(imageAddress) |
||||
.then(lenna => { |
||||
return lenna |
||||
.resize(157, 142) // resize
|
||||
.quality(90) // set JPEG quality
|
||||
.write(`./public/images/resized/${imageNameWithOutExtn}.png`); // save
|
||||
}) |
||||
.then((res)=>{ |
||||
try { |
||||
|
||||
fs.unlinkSync(__dirname + '/../public/images/' + image) |
||||
console.log('original picture is deleted .....') |
||||
console.log('----------------------------') |
||||
} catch (err) { |
||||
console.log(err); |
||||
console.log('original picture not deleted .....') |
||||
} |
||||
resolve(res) |
||||
}) |
||||
.catch(err => { |
||||
reject(err) |
||||
}); |
||||
}) |
||||
|
||||
} |
Loading…
Reference in new issue