File tree 1 file changed +8
-13
lines changed
1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -289,25 +289,20 @@ canvas.addEventListener('mousemove', function(e) {
289
289
canvas . addEventListener ( 'drop' , function ( e ) {
290
290
e . preventDefault ( ) ;
291
291
var file = e . dataTransfer . files [ 0 ] ;
292
+
293
+ // only allow image files
294
+ var supportedImageTypes = [ 'image/png' , 'image/jpeg' , 'image/jpg' , 'image/webp' ] ;
295
+ if ( ! supportedImageTypes . includes ( file . type ) ) {
296
+ alert ( 'Only PNG, JPEG, JPG, and WebP files are allowed.' ) ;
297
+ return ;
298
+ }
299
+
292
300
var reader = new FileReader ( ) ;
293
-
294
301
reader . onload = function ( event ) {
295
- // only allow image files
296
302
img . src = event . target . result ;
297
303
} ;
298
304
reader . readAsDataURL ( file ) ;
299
305
300
- var mime_type = file . type ;
301
-
302
- if (
303
- mime_type != 'image/png' &&
304
- mime_type != 'image/jpeg' &&
305
- mime_type != 'image/jpg'
306
- ) {
307
- alert ( 'Only PNG, JPEG, and JPG files are allowed.' ) ;
308
- return ;
309
- }
310
-
311
306
img . onload = function ( ) {
312
307
scaleFactor = 0.25 ;
313
308
canvas . style . width = img . width * scaleFactor + 'px' ;
You can’t perform that action at this time.
0 commit comments