@@ -63,41 +63,46 @@ describe('Rotation', function () {
6363 } ) ;
6464 } ) ;
6565
66- [ 90 , 180 , 270 , 45 ] . forEach ( function ( angle ) {
67- const [ inputWidth , inputHeight ] = orientation === 'Landscape' ? [ 600 , 450 ] : [ 450 , 600 ] ;
68- const expectedOutput = fixtures . expected ( `${ orientation } _${ exifTag } _rotate${ angle } -out.jpg` ) ;
69- it ( `${ orientation } image with EXIF Orientation ${ exifTag } : Auto-rotate then rotate ${ angle } ` , function ( done ) {
70- const [ width , height ] = angle === 45 ? [ 742 , 742 ] : [ inputWidth , inputHeight ] ;
71- const [ expectedWidth , expectedHeight ] = angle % 180 === 0 ? [ width , height ] : [ height , width ] ;
72-
73- sharp ( input )
74- . rotate ( )
75- . rotate ( angle )
76- . toBuffer ( function ( err , data , info ) {
66+ [ true , false ] . forEach ( ( doResize ) => {
67+ [ 90 , 180 , 270 , 45 ] . forEach ( function ( angle ) {
68+ const [ inputWidth , inputHeight ] = orientation === 'Landscape' ? [ 600 , 450 ] : [ 450 , 600 ] ;
69+ const expectedOutput = fixtures . expected ( `${ orientation } _${ exifTag } _rotate${ angle } -out.jpg` ) ;
70+ it ( `${ orientation } image with EXIF Orientation ${ exifTag } : Auto-rotate then rotate ${ angle } ${ doResize ? 'and resize' : '' } ` , function ( done ) {
71+ const [ width , height ] = ( angle === 45 ? [ 742 , 742 ] : [ inputWidth , inputHeight ] ) . map ( ( x ) => doResize ? Math . floor ( x / 1.875 ) : x ) ;
72+ const [ expectedWidth , expectedHeight ] = angle % 180 === 0 ? [ width , height ] : [ height , width ] ;
73+
74+ const img = sharp ( input )
75+ . rotate ( )
76+ . rotate ( angle ) ;
77+ doResize && img . resize ( expectedWidth ) ;
78+
79+ img . toBuffer ( function ( err , data , info ) {
7780 if ( err ) throw err ;
7881 assert . strictEqual ( info . width , expectedWidth ) ;
7982 assert . strictEqual ( info . height , expectedHeight ) ;
8083 fixtures . assertSimilar ( expectedOutput , data , done ) ;
8184 } ) ;
85+ } ) ;
8286 } ) ;
83- } ) ;
8487
85- [ [ true , true ] , [ true , false ] , [ false , true ] ] . forEach ( function ( [ flip , flop ] ) {
86- const [ inputWidth , inputHeight ] = orientation === 'Landscape' ? [ 600 , 450 ] : [ 450 , 600 ] ;
87- const flipFlopFileName = [ flip && 'flip' , flop && 'flop' ] . filter ( Boolean ) . join ( '_' ) ;
88- const flipFlopTestName = [ flip && 'flip' , flop && 'flop' ] . filter ( Boolean ) . join ( ' & ' ) ;
89- it ( `${ orientation } image with EXIF Orientation ${ exifTag } : Auto-rotate then ${ flipFlopTestName } ` , function ( done ) {
90- const expectedOutput = fixtures . expected ( `${ orientation } _${ exifTag } _${ flipFlopFileName } -out.jpg` ) ;
88+ [ [ true , true ] , [ true , false ] , [ false , true ] ] . forEach ( function ( [ flip , flop ] ) {
89+ const [ inputWidth , inputHeight ] = orientation === 'Landscape' ? [ 600 , 450 ] : [ 450 , 600 ] ;
90+ const flipFlopFileName = [ flip && 'flip' , flop && 'flop' ] . filter ( Boolean ) . join ( '_' ) ;
91+ const flipFlopTestName = [ flip && 'flip' , flop && 'flop' ] . filter ( Boolean ) . join ( ' & ' ) ;
92+ it ( `${ orientation } image with EXIF Orientation ${ exifTag } : Auto-rotate then ${ flipFlopTestName } ${ doResize ? 'and resize' : '' } ` , function ( done ) {
93+ const expectedOutput = fixtures . expected ( `${ orientation } _${ exifTag } _${ flipFlopFileName } -out.jpg` ) ;
9194
92- const img = sharp ( input ) . rotate ( ) ;
93- flip && img . flip ( ) ;
94- flop && img . flop ( ) ;
95+ const img = sharp ( input ) . rotate ( ) ;
96+ flip && img . flip ( ) ;
97+ flop && img . flop ( ) ;
98+ doResize && img . resize ( orientation === 'Landscape' ? 320 : 240 ) ;
9599
96- img . toBuffer ( function ( err , data , info ) {
97- if ( err ) throw err ;
98- assert . strictEqual ( info . width , inputWidth ) ;
99- assert . strictEqual ( info . height , inputHeight ) ;
100- fixtures . assertSimilar ( expectedOutput , data , done ) ;
100+ img . toBuffer ( function ( err , data , info ) {
101+ if ( err ) throw err ;
102+ assert . strictEqual ( info . width , inputWidth / ( doResize ? 1.875 : 1 ) ) ;
103+ assert . strictEqual ( info . height , inputHeight / ( doResize ? 1.875 : 1 ) ) ;
104+ fixtures . assertSimilar ( expectedOutput , data , done ) ;
105+ } ) ;
101106 } ) ;
102107 } ) ;
103108 } ) ;
0 commit comments