Skip to content

Commit

Permalink
Expose file to buffer optimization method
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptex committed Oct 19, 2020
1 parent 2229350 commit 562f84c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ const spinner = ora({
spinner: 'bouncingBall'
}).start();

/**
* Resize an image using Sharp
*
* @param {Object} params
* @param {String} file
*
* @return {Promise<Buffer | void>}
*/
const optisizeFile = async (params, file) => {
return await sharp(file)
.resize(params.width, params.height)
.toBuffer()
.then(buffer => imagemin.buffer(buffer, { plugins }))
.then(buffer => {
spinner.succeed(`Optisized ${file}`);

return buffer;
})
.catch(err => {
spinner.fail(`Optisize failed. Output: ${err}`);
});
};

/**
* Resize an image using Sharp
*
Expand Down Expand Up @@ -107,4 +130,5 @@ const optisize = async (params = {}) => {
};

module.exports = optisize;
module.exports.optisizeFile = optisizeFile;
module.exports.optisizeSingle = optisizeSingle;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@three11/optisize",
"version": "1.2.0",
"version": "1.3.0",
"description": "Resize and optimize images in a folder with nodejs",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 562f84c

Please sign in to comment.