@@ -12,11 +12,11 @@ if (process.argv.length < 4) {
1212 process . exit ( 64 ) ;
1313}
1414
15- const img1Path = process . argv [ 2 ] ;
16- const img2Path = process . argv [ 3 ] ;
17- const diffPath = process . argv [ 4 ] ;
18- const threshold = isNaN ( + process . argv [ 5 ] ) ? undefined : + process . argv [ 5 ] ;
19- const includeAA = process . argv [ 6 ] === 'true' ;
15+ const [ , , img1Path , img2Path , diffPath , threshold , includeAA ] = process . argv ;
16+ const options = {
17+ threshold : + threshold ,
18+ includeAA : includeAA !== undefined && includeAA !== 'false'
19+ } ;
2020
2121const img1 = PNG . sync . read ( fs . readFileSync ( img1Path ) ) ;
2222const img2 = PNG . sync . read ( fs . readFileSync ( img2Path ) ) ;
@@ -31,15 +31,13 @@ if (img2.width !== width || img2.height !== height) {
3131const diff = diffPath ? new PNG ( { width, height} ) : null ;
3232
3333console . time ( 'matched in' ) ;
34- const diffs = match ( img1 . data , img2 . data , diff ? diff . data : null , width , height , { threshold , includeAA } ) ;
34+ const diffs = match ( img1 . data , img2 . data , diff ? diff . data : null , width , height , options ) ;
3535console . timeEnd ( 'matched in' ) ;
3636
3737console . log ( `different pixels: ${ diffs } ` ) ;
3838console . log ( `error: ${ Math . round ( 100 * 100 * diffs / ( width * height ) ) / 100 } %` ) ;
3939
40- const exitCode = diffs ? 66 : 0 ;
41-
4240if ( diff ) {
4341 fs . writeFileSync ( diffPath , PNG . sync . write ( diff ) ) ;
4442}
45- process . exit ( exitCode ) ;
43+ process . exit ( diffs ? 66 : 0 ) ;
0 commit comments