Node module for using smartcrop via sharp/libvips
Switch branches/tags
Nothing to show
Clone or download
Latest commit 942e174 Apr 18, 2018
Failed to load latest commit information.
test eslint + prettier Feb 12, 2018
.editorconfig init Jun 19, 2016
.eslintrc.js eslint + prettier Feb 12, 2018
.gitignore init Jun 19, 2016
.jscsrc init Jun 19, 2016
.jshintrc init Jun 19, 2016
.npmignore Update smartcrop.js Sep 16, 2016
.travis.yml add sharp to dev dependencies Feb 11, 2018
.vimrc init Jun 19, 2016
LICENSE Create LICENSE Feb 12, 2018 Update Feb 12, 2018
index.js eslint + prettier Feb 12, 2018
package-lock.json Bump sharp Apr 18, 2018
package.json Bump sharp Apr 18, 2018


Build Status

This is an adapter module for using smartcrop.js with node.js using sharp for image decoding.


You'll need to install sharp alongside smartcrop-sharp.

npm install --save smartcrop-sharp sharp


crop(image, options)

Image: string (path to file) or buffer

Options: options object to be passed to smartcrop

returns: A promise for a cropResult


var request = require('request');
var sharp = require('sharp');
var smartcrop = require('smartcrop-sharp');

function applySmartCrop(src, dest, width, height) {
  request(src, { encoding: null }, function process(error, response, body) {
    if (error) return console.error(error);
    smartcrop.crop(body, { width: width, height: height }).then(function(result) {
      var crop = result.topCrop;
        .extract({ width: crop.width, height: crop.height, left: crop.x, top: crop.y })
        .resize(width, height)

var src = '';
applySmartCrop(src, 'flower-square.jpg', 128, 128);

Face Detection Example

Check out smartcrop-cli for a more advanced example of how to use smartcrop from node including face detection with opencv.



  • sharp is now a peer dependency you will need to install it via npm install sharp when updating
  • In short: It's a lot faster, especially when calculating bigger crops.
  • The quality of the crops should be comparable but the exact results are going to be different.