@@ -37,7 +37,10 @@ export default {
3737 return ( typeof num === 'number' ) ;
3838 } ;
3939 // check crop options
40- if ( checkNumber ( options . toCropImgX ) && checkNumber ( options . toCropImgY ) && options . toCropImgW > 0 && options . toCropImgH > 0 ) {
40+ if ( checkNumber ( options . toCropImgX ) &&
41+ checkNumber ( options . toCropImgY ) &&
42+ options . toCropImgW > 0 &&
43+ options . toCropImgH > 0 ) {
4144 let w = options . toCropImgW ;
4245 let h = options . toCropImgH ;
4346 if ( options . maxWidth && options . maxWidth < w ) {
@@ -80,24 +83,30 @@ export default {
8083 ctx . save ( ) ;
8184 ctx . translate ( canvasWidth / 2 , canvasWidth / 2 ) ;
8285 ctx . rotate ( degrees * ( Math . PI / 180 ) ) ;
83- const x = - canvasWidth / 2 ;
84- degrees = degrees % 360 ;
86+ let x = 0 ;
87+ degrees %= 360 ;
8588 if ( degrees === 0 ) {
8689 return callback ( src , w , h ) ;
8790 }
88- let y = ( ( canvasWidth - h ) - canvasWidth / 2 )
91+ let y = 0 ;
8992 if ( ( degrees % 180 ) !== 0 ) {
93+
94+ if ( degrees === - 90 || degrees === 270 ) {
95+ x = - h ;
96+ } else {
97+ y = - w ;
98+ }
9099 const c = w ;
91100 w = h ;
92101 h = c ;
93- if ( degrees === - 90 || degrees === 270 ) {
94- y = - canvasWidth / 2 ;
95- }
102+ cvs . width = w ;
103+ cvs . height = h ;
104+ } else {
105+ x = - w ;
106+ y = - h ;
96107 }
97108 ctx . drawImage ( image , x , y ) ;
98109 ctx . restore ( ) ;
99- //cvs.width = h;
100- //cvs.height = w;
101110 const mimeType = this . _getImageType ( image . src ) ;
102111 const data = cvs . toDataURL ( mimeType , 1 ) ;
103112 callback ( data , w , h ) ;
0 commit comments