New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

smartcrop-sharp

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smartcrop-sharp

smartcrop adapter for sharp

1.0.3
Version published
Weekly downloads
17K
-16.87%
Maintainers
1
Weekly downloads
 
Created

smartcrop-sharp

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);


FAQs

Package last updated on 25 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts