Skip to content

Commit 2ae0970

Browse files
committed
eslint + prettier
1 parent 6483154 commit 2ae0970

File tree

6 files changed

+1548
-34
lines changed

6 files changed

+1548
-34
lines changed

.eslintrc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
es6: true
5+
},
6+
extends: 'eslint:recommended',
7+
rules: {
8+
indent: ['error', 2],
9+
'linebreak-style': ['error', 'unix'],
10+
quotes: ['error', 'single'],
11+
semi: ['error', 'always']
12+
},
13+
overrides: [
14+
{
15+
files: ['test/*.js'],
16+
rules: { 'no-console': 'off' },
17+
env: {
18+
node: true,
19+
mocha: true
20+
}
21+
}
22+
]
23+
};

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ var sharp = require('sharp');
3131
var smartcrop = require('smartcrop-sharp');
3232

3333
function applySmartCrop(src, dest, width, height) {
34-
request(src, {encoding: null}, function process(error, response, body) {
34+
request(src, { encoding: null }, function process(error, response, body) {
3535
if (error) return console.error(error);
36-
smartcrop.crop(body, {width: width, height: height}).then(function(result) {
36+
smartcrop.crop(body, { width: width, height: height }).then(function(result) {
3737
var crop = result.topCrop;
3838
sharp(body)
39-
.extract({width: crop.width, height: crop.height, left: crop.x, top: crop.y})
39+
.extract({ width: crop.width, height: crop.height, left: crop.x, top: crop.y })
4040
.resize(width, height)
4141
.toFile(dest);
4242
});
@@ -45,13 +45,11 @@ function applySmartCrop(src, dest, width, height) {
4545

4646
var src = 'https://raw.githubusercontent.com/jwagner/smartcrop-gm/master/test/flower.jpg';
4747
applySmartCrop(src, 'flower-square.jpg', 128, 128);
48-
49-
5048
```
5149

5250
## Face Detection Example
53-
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.
5451

52+
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.
5553

5654
## Changelog
5755

index.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ var sharp = require('sharp');
33

44
function rgb2rgba(input) {
55
var output = new Buffer(input.length / 3 * 4);
6-
for (var i = 0; i < input.length;i += 3) {
6+
for (var i = 0; i < input.length; i += 3) {
77
output[i / 3 * 4] = input[i];
88
output[i / 3 * 4 + 1] = input[i + 1];
99
output[i / 3 * 4 + 2] = input[i + 2];
1010
output[i / 3 * 4 + 3] = 255;
11-
1211
}
1312
return output;
1413
}
@@ -20,23 +19,23 @@ var iop = {
2019
return {
2120
width: metadata.width,
2221
height: metadata.height,
23-
_sharp: image,
22+
_sharp: image
2423
};
2524
});
2625
},
2726
resample: function(image, width, height) {
2827
// this does not clone the image, better performance but fragile
2928
// (depends on the assumtion that resample+getData is only called once per img)
30-
return new Promise(function(resolve, reject) {
29+
return new Promise(function(resolve) {
3130
resolve({
3231
width: ~~width,
3332
height: ~~height,
34-
_sharp: image._sharp,
33+
_sharp: image._sharp
3534
});
3635
});
3736
},
3837
getData: function(image) {
39-
var options = {kernel: sharp.kernel.cubic, interpolator: sharp.interpolator.bilinear};
38+
var options = { kernel: sharp.kernel.cubic };
4039
return image._sharp
4140
.resize(image.width, image.height, options)
4241
.raw()
@@ -46,20 +45,15 @@ var iop = {
4645
data = rgb2rgba(data);
4746
}
4847
if (data.length !== image.width * image.height * 4) {
49-
console.log(image.width, image.height);
50-
throw new Error('unexpected data length ' + data.length);
48+
throw new Error('unexpected data length ' + data.length);
5149
}
5250
return new smartcrop.ImgData(image.width, image.height, data);
5351
});
54-
},
52+
}
5553
};
5654

5755
exports.crop = function(img, options, callback) {
5856
options = options || {};
5957
options.imageOperations = iop;
6058
return smartcrop.crop(img, options, callback);
6159
};
62-
63-
// exports.crop('kitty.jpg').then(function() {
64-
// console.log(arguments);
65-
// });

0 commit comments

Comments
 (0)