@@ -691,6 +691,10 @@ const compress = async (info: any) => {
691691 const sourceExt = path . extname ( info . source ) . replaceAll ( "." , "" )
692692 const ext = path . extname ( dest ) . replaceAll ( "." , "" )
693693 const resizeCondition = options . keepRatio ? ( options . percentage ? options . resizeWidth !== 100 : true ) : ( options . percentage ? ( options . resizeWidth !== 100 && options . resizeHeight !== 100 ) : true )
694+ let isAnimated = sourceExt === "gif"
695+ if ( sourceExt === "webp" ) {
696+ isAnimated = functions . isAnimatedWebp ( buffer )
697+ }
694698 if ( ext === "gif" ) {
695699 if ( resizeCondition ) {
696700 if ( process . platform === "win32" ) {
@@ -733,12 +737,14 @@ const compress = async (info: any) => {
733737 buffer = await s . toBuffer ( )
734738 }
735739 if ( options . quality !== 100 ) {
736- buffer = await imagemin . buffer ( buffer , { plugins : [
737- imageminMozjpeg ( { quality : options . quality } ) ,
738- imageminPngquant ( ) ,
739- imageminWebp ( { quality : options . quality } ) ,
740- imageminGifsicle ( { optimizationLevel : 3 } )
741- ] } )
740+ if ( ! isAnimated && ext !== "avif" && ext !== "jxl" ) {
741+ buffer = await imagemin . buffer ( buffer , { plugins : [
742+ imageminMozjpeg ( { quality : options . quality } ) ,
743+ imageminPngquant ( ) ,
744+ imageminWebp ( { quality : options . quality } ) ,
745+ imageminGifsicle ( { optimizationLevel : 3 } )
746+ ] } )
747+ }
742748 }
743749 }
744750 fs . writeFileSync ( options . overwrite ? info . source : dest , buffer )
@@ -803,6 +809,10 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
803809 const sourceExt = path . extname ( info . source ) . replaceAll ( "." , "" )
804810 const ext = path . extname ( dest ) . replaceAll ( "." , "" )
805811 const resizeCondition = options . keepRatio ? ( options . percentage ? options . resizeWidth !== 100 : true ) : ( options . percentage ? ( options . resizeWidth !== 100 && options . resizeHeight !== 100 ) : true )
812+ let isAnimated = sourceExt === "gif"
813+ if ( sourceExt === "webp" ) {
814+ isAnimated = functions . isAnimatedWebp ( buffer )
815+ }
806816 if ( ext === "gif" ) {
807817 if ( resizeCondition ) {
808818 if ( process . platform === "win32" ) {
@@ -845,12 +855,14 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
845855 buffer = await s . toBuffer ( )
846856 }
847857 if ( options . quality !== 100 ) {
848- buffer = await imagemin . buffer ( buffer , { plugins : [
849- imageminMozjpeg ( { quality : options . quality } ) ,
850- imageminPngquant ( ) ,
851- imageminWebp ( { quality : options . quality } ) ,
852- imageminGifsicle ( { optimizationLevel : 3 } )
853- ] } )
858+ if ( ! isAnimated && ext !== "avif" && ext !== "jxl" ) {
859+ buffer = await imagemin . buffer ( buffer , { plugins : [
860+ imageminMozjpeg ( { quality : options . quality } ) ,
861+ imageminPngquant ( ) ,
862+ imageminWebp ( { quality : options . quality } ) ,
863+ imageminGifsicle ( { optimizationLevel : 3 } )
864+ ] } )
865+ }
854866 }
855867 }
856868 return { buffer, fileSize : Buffer . byteLength ( buffer ) }
0 commit comments