Skip to content

Commit 1be7ace

Browse files
committed
Merge pull request jwagner#6 from pjackowski/master
Simplified two if statements.
2 parents 08a577a + 8c9aa2a commit 1be7ace

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

smartcrop.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ SmartCrop.crop = function(image, options, callback){
8383
scale = min(image.width/options.width, image.height/options.height);
8484
options.cropWidth = ~~(options.width * scale);
8585
options.cropHeight = ~~(options.height * scale);
86-
// img = 100x100, width = 95x95, scale = 100/95, 1/scale > min
86+
// img = 100x100, width = 95x95, scale = 100/95, 1/scale > min
8787
// don't set minscale smaller than 1/scale
8888
// -> don't pick crops that need upscaling
8989
options.minScale = min(options.maxScale || SmartCrop.DEFAULTS.maxScale, max(1/scale, (options.minScale||SmartCrop.DEFAULTS.minScale)));
@@ -121,8 +121,7 @@ SmartCrop.isAvailable = function(options){
121121
try {
122122
var s = new this(options),
123123
c = s.canvas(16, 16);
124-
if(typeof c.getContext !== 'function') return false;
125-
return true;
124+
return typeof c.getContext === 'function';
126125
}
127126
catch(e){
128127
return false;
@@ -305,7 +304,7 @@ SmartCrop.prototype = {
305304
topCrop = crop;
306305
topScore = crop.score.total;
307306
}
308-
307+
309308
}
310309

311310
result.crops = crops;
@@ -314,23 +313,21 @@ SmartCrop.prototype = {
314313
if(options.debug && topCrop){
315314
ctx.fillStyle = 'rgba(255, 0, 0, 0.1)';
316315
ctx.fillRect(topCrop.x, topCrop.y, topCrop.width, topCrop.height);
317-
if(true){
318-
for(var y = 0; y < output.height; y++) {
319-
for(var x = 0; x < output.width; x++) {
320-
var p = (y*output.width+x)*4;
321-
var importance = this.importance(topCrop, x, y);
322-
if(importance > 0) {
323-
output.data[p+1] += importance*32;
324-
}
316+
for (var y = 0; y < output.height; y++) {
317+
for (var x = 0; x < output.width; x++) {
318+
var p = (y * output.width + x) * 4;
319+
var importance = this.importance(topCrop, x, y);
320+
if (importance > 0) {
321+
output.data[p + 1] += importance * 32;
322+
}
325323

326-
if(importance < 0) {
327-
output.data[p] += importance*-64;
328-
}
329-
output.data[p+3] = 255;
324+
if (importance < 0) {
325+
output.data[p] += importance * -64;
330326
}
327+
output.data[p + 3] = 255;
331328
}
332-
ctx.putImageData(output, 0, 0);
333329
}
330+
ctx.putImageData(output, 0, 0);
334331
ctx.strokeStyle = 'rgba(255, 0, 0, 0.8)';
335332
ctx.strokeRect(topCrop.x, topCrop.y, topCrop.width, topCrop.height);
336333
result.debugCanvas = canvas;
@@ -381,11 +378,6 @@ function saturation(r, g, b){
381378
return l > 0.5 ? d/(2-maximum-minumum) : d/(maximum+minumum);
382379
}
383380

384-
385-
386-
387-
388-
389381
// amd
390382
if (typeof define !== 'undefined' && define.amd) define(function(){return SmartCrop;});
391383
//common js

0 commit comments

Comments
 (0)