@@ -18,7 +18,6 @@ function sliceImage(filename, width, height, canvasWidth, canvasHeight, scale, c
1818 // Continue slicing if image is successfully read
1919 if ( image ) {
2020 continueSlicing ( image , width , height , canvasWidth , canvasHeight , scale , cubic , filename ) ;
21- return ;
2221 }
2322 }
2423 } ) ;
@@ -29,26 +28,27 @@ function sliceImage(filename, width, height, canvasWidth, canvasHeight, scale, c
2928 const supportedFormats = [ '.png' , '.gif' , '.jpg' , '.jpeg' ] ;
3029 let foundImage = false ;
3130 // Attempt to read the image with different extensions
32- supportedFormats . forEach ( ( ext ) => {
31+ supportedFormats . forEach ( async ( ext , index ) => {
3332 const fullFilename = filename + ext ;
3433 if ( ! foundImage ) {
35- Jimp . read ( fullFilename , ( err , image ) => {
36- if ( ! foundImage && ! err ) {
37- foundImage = true ;
38- continueSlicing ( image , width , height , canvasWidth , canvasHeight , scale , cubic , fullFilename ) ;
39- }
40- } ) ;
34+ try {
35+ const image = await Jimp . read ( fullFilename ) ;
36+ foundImage = true ;
37+ continueSlicing ( image , width , height , canvasWidth , canvasHeight , scale , cubic , fullFilename ) ;
38+ }
39+ catch ( err ) { }
40+ if ( ! foundImage && index === supportedFormats . length - 1 ) {
41+ console . error ( `Could not find ${ filename } ` ) ;
42+ }
4143 }
4244 } ) ;
43- if ( foundImage === false ) {
44- throw new Error ( `Could not find ${ filename } ` ) ;
45- }
4645}
4746exports . sliceImage = sliceImage ;
4847/**
4948 * Continue slicing the image into smaller segments
5049 */
5150function continueSlicing ( image , width , height , canvasWidth , canvasHeight , scale , cubic , inputFilename ) {
51+ console . time ( 'Done in' ) ;
5252 // If height is not specified, use width as height
5353 height = height || width ;
5454 const imageWidth = image . getWidth ( ) ;
@@ -95,6 +95,7 @@ function continueSlicing(image, width, height, canvasWidth, canvasHeight, scale,
9595 console . log ( `Slice saved: ${ outputFilename } ` ) ;
9696 }
9797 }
98+ console . timeEnd ( 'Done in' ) ;
9899}
99100// If used as a worker thread, get file name from message
100101if ( ! worker_threads_1 . isMainThread ) {
0 commit comments