Skip to content

Repository files navigation

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

varrequest=require('request');varsharp=require('sharp');varsmartcrop=require('smartcrop-sharp');functionapplySmartCrop(src,dest,width,height){request(src,{encoding: null},functionprocess(error,response,body){if(error)returnconsole.error(error);smartcrop.crop(body,{width: width,height: height}).then(function(result){varcrop=result.topCrop;sharp(body).extract({width: crop.width,height: crop.height,left: crop.x,top: crop.y}).resize(width,height).toFile(dest);});});}varsrc='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.

About

Node module for using smartcrop via sharp/libvips

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages