Node module for using smartcrop via sharp/libvips
JavaScript VimL
Latest commit bf7ead3 Sep 16, 2016 @jwagner Update smartcrop.js
Permalink
Failed to load latest commit information.
test Dependency hell Jun 25, 2016
.editorconfig init Jun 19, 2016
.gitignore init Jun 19, 2016
.jscsrc init Jun 19, 2016
.jshintrc init Jun 19, 2016
.npmignore Update smartcrop.js Sep 16, 2016
.travis.yml try to fix os x builds Aug 21, 2016
.vimrc init Jun 19, 2016
README.md Update README.md Aug 21, 2016
index.js init Jun 19, 2016
package.json Update smartcrop.js Sep 16, 2016

README.md

smartcrop-sharp

Build Status

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

Installation

npm install --save smartcrop-sharp

API

crop(image, options)

Image: string (path to file) or buffer

Options: options object to be passed to smartcrop

returns: A promise for a cropResult

Example

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;
      sharp(body)
        .extract({width: crop.width, height: crop.height, left: crop.x, top: crop.y})
        .resize(width, height)
        .toFile(dest);
    });
  });
}

var src = 'https://raw.githubusercontent.com/jwagner/smartcrop-gm/master/test/flower.jpg';
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.