@@ -12,22 +12,26 @@ export default {
1212 }
1313 return mimeType ;
1414 } ,
15-
1615 compress ( src , quality , callback ) {
17- const reader = new FileReader ( ) ;
18- const self = this ;
19- reader . onload = function ( event ) {
20- const image = new Image ( ) ;
21- image . src = event . target . result ;
22- image . onload = function ( ) {
23- const mimeType = self . _getImageType ( src . type ) ;
24- const cvs = self . _getCanvas ( image . naturalWidth , image . naturalHeight ) ;
25- const ctx = cvs . getContext ( "2d" ) . drawImage ( image , 0 , 0 ) ;
26- const newImageData = cvs . toDataURL ( mimeType , quality / 100 ) ;
27- callback ( newImageData ) ;
28- }
29- } ;
30- reader . readAsDataURL ( src ) ;
16+ for ( var i = 0 ; i < src . length ; i ++ ) {
17+ const reader = new FileReader ( ) ;
18+ const self = this ;
19+ ( function ( file ) {
20+ reader . onload = ( function ( event ) {
21+ const image = new Image ( ) ;
22+ image . src = event . target . result ;
23+ image . onload = function ( ) {
24+ const mimeType = self . _getImageType ( file . type ) ;
25+ const cvs = self . _getCanvas ( image . naturalWidth , image . naturalHeight ) ;
26+ const ctx = cvs . getContext ( "2d" ) . drawImage ( image , 0 , 0 ) ;
27+ const newImageData = cvs . toDataURL ( mimeType , quality / 100 ) ;
28+ file [ 'base64Code' ] = newImageData ;
29+ callback ( file ) ;
30+ }
31+ } )
32+ } ) ( src [ i ] )
33+ reader . readAsDataURL ( src [ i ] ) ;
34+ }
3135 } ,
3236 /**
3337 * crop image via canvas and generate data
0 commit comments