@@ -53,37 +53,45 @@ async function convertImage(
5353 if ( formats . includes ( "jpeg" as any ) && [ ".jpg" , ".jpeg" ] . includes ( ext ) ) return ;
5454 if ( formats . includes ( "avif" as any ) && ext === ".avif" ) return ;
5555
56- const image = sharp ( sourcePath ) ;
57-
58- for ( const format of formats ) {
59- const outputPath = join ( dir , `${ name } .${ format } ` ) ;
60-
61- // 이미 변환된 파일이 있으면 스킵
62- if ( existsSync ( outputPath ) ) continue ;
63-
64- try {
65- if ( format === "webp" ) {
66- await image
67- . clone ( )
68- . webp ( { quality : options . webpQuality || 80 } )
69- . toFile ( outputPath ) ;
70- console . log ( `✅ WebP 생성: ${ outputPath } ` ) ;
71- } else if ( format === "jpeg" ) {
72- await image
73- . clone ( )
74- . jpeg ( { quality : options . jpegQuality || 80 } )
75- . toFile ( outputPath ) ;
76- console . log ( `✅ JPEG 생성: ${ outputPath } ` ) ;
77- } else if ( format === "avif" ) {
78- await image
79- . clone ( )
80- . avif ( { quality : options . avifQuality || 70 } )
81- . toFile ( outputPath ) ;
82- console . log ( `✅ AVIF 생성: ${ outputPath } ` ) ;
56+ try {
57+ const image = sharp ( sourcePath ) ;
58+
59+ for ( const format of formats ) {
60+ const outputPath = join ( dir , `${ name } .${ format } ` ) ;
61+
62+ // 이미 변환된 파일이 있으면 스킵
63+ if ( existsSync ( outputPath ) ) continue ;
64+
65+ try {
66+ if ( format === "webp" ) {
67+ await image
68+ . clone ( )
69+ . webp ( { quality : options . webpQuality || 80 } )
70+ . toFile ( outputPath ) ;
71+ console . log ( `✅ WebP 생성: ${ outputPath } ` ) ;
72+ } else if ( format === "jpeg" ) {
73+ await image
74+ . clone ( )
75+ . jpeg ( { quality : options . jpegQuality || 80 } )
76+ . toFile ( outputPath ) ;
77+ console . log ( `✅ JPEG 생성: ${ outputPath } ` ) ;
78+ } else if ( format === "avif" ) {
79+ await image
80+ . clone ( )
81+ . avif ( { quality : options . avifQuality || 70 } )
82+ . toFile ( outputPath ) ;
83+ console . log ( `✅ AVIF 생성: ${ outputPath } ` ) ;
84+ }
85+ } catch ( error ) {
86+ console . warn (
87+ `⚠️ ${ format . toUpperCase ( ) } 변환 실패 (${ basename ( sourcePath ) } ): ${ error instanceof Error ? error . message : String ( error ) } ` ,
88+ ) ;
8389 }
84- } catch ( error ) {
85- console . warn ( `⚠️ 이미지 변환 실패 (${ sourcePath } ):` , error ) ;
8690 }
91+ } catch ( error ) {
92+ console . warn (
93+ `⚠️ 이미지 로드 실패 (${ basename ( sourcePath ) } ): ${ error instanceof Error ? error . message : String ( error ) } . 원본 파일을 사용합니다.` ,
94+ ) ;
8795 }
8896}
8997
0 commit comments