@@ -70,24 +70,27 @@ export default {
7070 }
7171 } ,
7272
73- rotate ( src , degress , callback ) {
73+ rotate ( src , degrees , callback ) {
7474 this . _loadImage ( src , ( image ) => {
7575 let w = image . naturalWidth ;
7676 let h = image . naturalHeight ;
7777 const canvasWidth = Math . max ( w , h ) ;
7878 const cvs = this . _getCanvas ( canvasWidth , canvasWidth ) ;
79- const ctx = cvs . getContext ( '2d' ) . drawImage ( image , ( canvasWidth - w ) / 2 , ( canvasWidth - h ) / 2 ) ;
79+ const targetCvs = this . _getCanvas ( h , w ) ;
80+ const ctx = cvs . getContext ( '2d' ) ;
81+ ctx . drawImage ( image , ( canvasWidth - w ) / 2 , ( canvasWidth - h ) / 2 ) ;
8082 ctx . clearRect ( 0 , 0 , canvasWidth , canvasWidth ) ;
8183 ctx . save ( ) ;
8284 ctx . translate ( canvasWidth / 2 , canvasWidth / 2 ) ;
83- ctx . rotate ( degrees * ( Math . PI / 180 ) ) ;
84- ctx . drawImage ( image , - image . width / 2 , - image . width / 2 ) ;
85+ ctx . rotate ( degrees * ( Math . PI / 180 ) ) ;
86+ cvs . width = h ;
87+ cvs . height = w ;
88+ ctx . drawImage ( image , - ( ( image . width - image . height ) / 2 ) , - ( ( image . width - image . height ) / 2 ) ) ;
8589 ctx . restore ( ) ;
8690 const mimeType = this . _getImageType ( image . src ) ;
87- const data = cvs . toDataURL ( mimeType , options . compress / 100 ) ;
88- callback ( data ) ;
91+ const data = cvs . toDataURL ( mimeType , 1 ) ;
92+ callback ( data , h , w ) ;
8993 } ) ;
90-
9194 } ,
9295
9396 _loadImage ( data , callback ) {
0 commit comments