Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smartcrop-sharp

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smartcrop-sharp - npm Package Compare versions

Comparing version 2.0.0 to 2.0.2

.eslintrc.js

20

index.js

@@ -6,3 +6,3 @@ var smartcrop = require('smartcrop');

var output = new Buffer(input.length / 3 * 4);
for (var i = 0; i < input.length;i += 3) {
for (var i = 0; i < input.length; i += 3) {
output[i / 3 * 4] = input[i];

@@ -12,3 +12,2 @@ output[i / 3 * 4 + 1] = input[i + 1];

output[i / 3 * 4 + 3] = 255;
}

@@ -25,3 +24,3 @@ return output;

height: metadata.height,
_sharp: image,
_sharp: image
};

@@ -33,7 +32,7 @@ });

// (depends on the assumtion that resample+getData is only called once per img)
return new Promise(function(resolve, reject) {
return new Promise(function(resolve) {
resolve({
width: ~~width,
height: ~~height,
_sharp: image._sharp,
_sharp: image._sharp
});

@@ -43,3 +42,3 @@ });

getData: function(image) {
var options = {kernel: sharp.kernel.cubic, interpolator: sharp.interpolator.bilinear};
var options = { kernel: sharp.kernel.cubic };
return image._sharp

@@ -54,8 +53,7 @@ .resize(image.width, image.height, options)

if (data.length !== image.width * image.height * 4) {
console.log(image.width, image.height);
throw new Error('unexpected data length ' + data.length);
throw new Error('unexpected data length ' + data.length);
}
return new smartcrop.ImgData(image.width, image.height, data);
});
},
}
};

@@ -68,5 +66,1 @@

};
// exports.crop('kitty.jpg').then(function() {
// console.log(arguments);
// });
{
"name": "smartcrop-sharp",
"version": "2.0.0",
"version": "2.0.2",
"description": "smartcrop adapter for sharp",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec"
"test": "eslint index.js test/test.js && mocha --reporter spec"
},

@@ -12,9 +12,14 @@ "author": "Jonas Wagner <jonas@29a.ch>",

"dependencies": {
"sharp": "^0.16.0",
"smartcrop": "^2.0.1"
"smartcrop": "^2.0.2"
},
"peerDependencies": {
"sharp": "^0.19.0"
},
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.0.2"
"chai": "^4.1.2",
"eslint": "^4.17.0",
"mocha": "^5.0.0",
"prettier-eslint": "^8.8.1",
"sharp": "^0.19.0"
}
}

@@ -9,4 +9,7 @@ # smartcrop-sharp

## Installation
You'll need to install `sharp` alongside `smartcrop-sharp`.
```
npm install --save smartcrop-sharp
npm install --save smartcrop-sharp sharp
```

@@ -32,8 +35,8 @@

function applySmartCrop(src, dest, width, height) {
request(src, {encoding: null}, function process(error, response, body) {
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) {
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})
.extract({ width: crop.width, height: crop.height, left: crop.x, top: crop.y })
.resize(width, height)

@@ -47,14 +50,14 @@ .toFile(dest);

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.
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.
## Changelog
### 2.0 (beta)
### 2.0.2
It's faster.
**sharp is now a peer dependency you will need to install it via `npm install sharp` when updating**
In short: It's a lot faster, especially when calculating bigger crops.
The quality of the crops should be comparable but the exact results are going to be different.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc