@@ -25,7 +25,7 @@ function b64toBlob(b64Data, contentType = '', sliceSize = 512) {
25
25
return blob ;
26
26
}
27
27
28
- function getLightestRow ( imageData , padding ) {
28
+ function getDarkestRow ( imageData , padding ) {
29
29
return new Promise ( ( resolve , reject ) => {
30
30
let img = new Image ( ) ;
31
31
img . onload = function ( ) {
@@ -37,8 +37,8 @@ function getLightestRow(imageData, padding) {
37
37
38
38
ctx . drawImage ( this , 0 , 0 , this . width , this . height ) ;
39
39
40
- let maxBrightness = 0 ;
41
- let maxBrightnessRowIndex = padding ;
40
+ let minBrightness = 0 ;
41
+ let minBrightnessRowIndex = padding ;
42
42
43
43
for ( let y = padding ; y < this . height - padding ; y += 5 ) {
44
44
let rowBrightness = 0 ;
@@ -57,14 +57,14 @@ function getLightestRow(imageData, padding) {
57
57
58
58
let averageRowBrightness = rowBrightness / count ; // divide by the number of pixels checked
59
59
60
- if ( averageRowBrightness > maxBrightness ) {
61
- maxBrightness = averageRowBrightness ;
62
- maxBrightnessRowIndex = y ;
60
+ if ( averageRowBrightness < minBrightness ) {
61
+ minBrightness = averageRowBrightness ;
62
+ minBrightnessRowIndex = y ;
63
63
}
64
64
}
65
65
66
66
// Convert row index to percentage
67
- let percentage = ( maxBrightnessRowIndex / this . height ) * 100 ;
67
+ let percentage = ( minBrightnessRowIndex / this . height ) * 100 ;
68
68
69
69
resolve ( percentage ) ;
70
70
} ;
@@ -97,16 +97,16 @@ export default class IllustratorIllustrationModel extends Model {
97
97
base64 ;
98
98
99
99
@attr ( 'number' )
100
- lightestRowPct ;
100
+ darkestRowPct ;
101
101
102
102
@task
103
- * setLightestRowPctTask ( ) {
103
+ * setDarkestRowPctTask ( ) {
104
104
const { url } = this ;
105
105
if ( ! url ) return ;
106
106
107
- const lightestRowPct = yield getLightestRow ( url , 50 ) ;
107
+ const darkestRowPct = yield getDarkestRow ( url , 50 ) ;
108
108
109
- this . lightestRowPct = lightestRowPct ;
109
+ this . darkestRowPct = darkestRowPct ;
110
110
}
111
111
112
112
get base64Data ( ) {
@@ -159,7 +159,7 @@ export default class IllustratorIllustrationModel extends Model {
159
159
const json = yield response . json ( ) ;
160
160
this . cost += COST_PER_IMAGE ;
161
161
this . base64 = json [ 'data' ] [ 0 ] [ 'b64_json' ] ;
162
- this . setLightestRowPctTask . perform ( ) ;
162
+ this . setDarkestRowPctTask . perform ( ) ;
163
163
}
164
164
}
165
165
}
0 commit comments