smartcrop-sharp
Advanced tools
Comparing version 2.0.0 to 2.0.2
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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5794
79
61
5
+ Addedchownr@1.1.4(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addeddetect-libc@1.0.3(transitive)
+ Addedfs-minipass@1.2.7(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addedminipass@2.9.0(transitive)
+ Addedminizlib@1.3.3(transitive)
+ Addedsharp@0.19.1(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@2.8.2(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedtar@4.4.19(transitive)
+ Addedyallist@3.1.1(transitive)
- Removedsharp@^0.16.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedblock-stream@0.0.9(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedclone@1.0.4(transitive)
- Removedcolor@0.11.4(transitive)
- Removedcolor-string@0.3.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfstream@1.0.12(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedglob@7.2.3(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsharp@0.16.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtar@2.2.2(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedsmartcrop@^2.0.2