23
23
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
*/
25
25
26
- // TODO: Penalty for detail/skin outside of viewport, reduce edge!
27
-
28
-
29
26
( function ( ) {
27
+ "use strict" ;
30
28
31
29
function SmartCrop ( options ) {
32
30
this . options = extend ( { } , SmartCrop . DEFAULTS , options ) ;
@@ -65,7 +63,7 @@ SmartCrop.DEFAULTS = {
65
63
} ;
66
64
SmartCrop . crop = function ( image , options , callback ) {
67
65
if ( options . aspect ) {
68
- options . width = aspect ;
66
+ options . width = options . aspect ;
69
67
options . height = 1 ;
70
68
}
71
69
@@ -175,7 +173,7 @@ SmartCrop.prototype = {
175
173
for ( var y = 0 ; y < h ; y ++ ) {
176
174
for ( var x = 0 ; x < w ; x ++ ) {
177
175
var p = ( y * w + x ) * 4 ,
178
- lightness = this . cie ( id [ p ] , id [ p + 1 ] , id [ p + 2 ] ) / 255 ;
176
+ lightness = this . cie ( id [ p ] , id [ p + 1 ] , id [ p + 2 ] ) / 255 ,
179
177
skin = this . skinColor ( id [ p ] , id [ p + 1 ] , id [ p + 2 ] ) ;
180
178
if ( skin > options . skinThreshold && lightness >= options . skinBrightnessMin && lightness <= options . skinBrightnessMax ) {
181
179
od [ p ] = ( skin - options . skinThreshold ) * ( 255 / ( 1 - options . skinThreshold ) ) ;
@@ -197,7 +195,7 @@ SmartCrop.prototype = {
197
195
for ( var y = 0 ; y < h ; y ++ ) {
198
196
for ( var x = 0 ; x < w ; x ++ ) {
199
197
var p = ( y * w + x ) * 4 ,
200
- lightness = this . cie ( id [ p ] , id [ p + 1 ] , id [ p + 2 ] ) / 255 ;
198
+ lightness = this . cie ( id [ p ] , id [ p + 1 ] , id [ p + 2 ] ) / 255 ,
201
199
saturation = this . saturation ( id [ p ] , id [ p + 1 ] , id [ p + 2 ] ) ;
202
200
if ( saturation > options . saturationThreshold && lightness >= options . saturationBrightnessMin && lightness <= options . saturationBrightnessMax ) {
203
201
od [ p + 2 ] = ( saturation - options . saturationThreshold ) * ( 255 / ( 1 - options . saturationThreshold ) ) ;
@@ -339,7 +337,7 @@ SmartCrop.prototype = {
339
337
topCrop = null ,
340
338
crops = this . crops ( image ) ;
341
339
342
- for ( i = 0 , i_len = crops . length ; i < i_len ; i ++ ) {
340
+ for ( var i = 0 , i_len = crops . length ; i < i_len ; i ++ ) {
343
341
var crop = crops [ i ] ;
344
342
crop . score = this . score ( scoreOutput , crop ) ;
345
343
if ( crop . score . total > topScore ) {
@@ -419,7 +417,7 @@ if (typeof define !== 'undefined' && define.amd) define(function(){return SmartC
419
417
//common js
420
418
if ( typeof exports !== 'undefined' ) exports . SmartCrop = SmartCrop ;
421
419
// browser
422
- else if ( typeof navigator !== 'undefined' ) this . SmartCrop = SmartCrop ;
420
+ else if ( typeof navigator !== 'undefined' ) window . SmartCrop = SmartCrop ;
423
421
// nodejs
424
422
if ( typeof module !== 'undefined' ) {
425
423
module . exports = SmartCrop ;
0 commit comments