https://github.com/dadi/smartcrop-sharp
https://github.com/dadi/smartcrop-sharp
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/dadi/smartcrop-sharp
- Owner: dadi
- Created: 2020-06-12T07:17:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-12T07:20:52.000Z (about 6 years ago)
- Last Synced: 2025-03-30T19:17:38.589Z (about 1 year ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# smartcrop-sharp
[](https://travis-ci.org/jwagner/smartcrop-sharp)
This is an adapter module for using [smartcrop.js](https://github.com/jwagner/smartcrop.js)
with node.js using [sharp](https://github.com/lovell/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
```javascript
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](https://github.com/jwagner/smartcrop-cli/) for a more advanced [example](https://github.com/jwagner/smartcrop-cli/blob/master/smartcrop-cli.js#L100) of how to use smartcrop from node including face detection with opencv.