smartcrop-jimp

1.0.3 • Public • Published

smartcrop-jimp

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

The reason why I wanted to use Jimp with smartcrop.js is that jimp doesn't have no native dependency: It's 100% javascript. So mixing smartcrop and jimp seemed to me super natural to use with NodeJS.

This module is widely inspired by Jonas Weigner's https://github.com/jwagner/smartcrop-sharp Thank you Jonas for smartcrop.js !

Installation

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

npm install --save smartcrop-jimp jimp

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 Jimp = require('jimp');
var smartcrop = require('smartcrop-jimp');

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;
      Jimp(body)
        .crop(crop.x, crop.y, crop.width, crop.height)
        .write(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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.33latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.33
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i smartcrop-jimp

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

6.54 kB

Total Files

9

Last publish

Collaborators

  • gregorybesson