File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -111,14 +111,18 @@ export function convertImage(blob, mime) {
111
111
const img = new Image ( ) ;
112
112
const canvas = document . createElement ( 'canvas' ) ;
113
113
img . addEventListener ( 'load' , ( ) => {
114
- canvas . width = img . naturalWidth ;
115
- canvas . height = img . naturalHeight ;
116
- const context = canvas . getContext ( '2d' ) ;
117
- context . drawImage ( img , 0 , 0 ) ;
118
- canvas . toBlob ( ( blob ) => {
119
- if ( ! ( blob instanceof Blob ) ) return reject ( new Error ( 'imageBlobToPng failed' ) ) ;
120
- resolve ( blob ) ;
121
- } , mime ) ;
114
+ try {
115
+ canvas . width = img . naturalWidth ;
116
+ canvas . height = img . naturalHeight ;
117
+ const context = canvas . getContext ( '2d' ) ;
118
+ context . drawImage ( img , 0 , 0 ) ;
119
+ canvas . toBlob ( ( blob ) => {
120
+ if ( ! ( blob instanceof Blob ) ) return reject ( new Error ( 'imageBlobToPng failed' ) ) ;
121
+ resolve ( blob ) ;
122
+ } , mime ) ;
123
+ } catch ( err ) {
124
+ reject ( err ) ;
125
+ }
122
126
} ) ;
123
127
img . addEventListener ( 'error' , ( ) => {
124
128
reject ( new Error ( 'imageBlobToPng failed' ) ) ;
You can’t perform that action at this time.
0 commit comments