@@ -658,7 +658,8 @@ const compress = async (info: any) => {
658658 percentage : info . percentage ,
659659 keepRatio : info . keepRatio ,
660660 rename : info . rename ,
661- format : info . format
661+ format : info . format ,
662+ progressive : info . progressive
662663 }
663664 window ?. webContents . send ( "conversion-started" , { id : info . id } )
664665 const fileSize = functions . parseFileSize ( info . fileSize )
@@ -692,15 +693,19 @@ const compress = async (info: any) => {
692693 const resizeCondition = options . keepRatio ? ( options . percentage ? options . resizeWidth !== 100 : true ) : ( options . percentage ? ( options . resizeWidth !== 100 && options . resizeHeight !== 100 ) : true )
693694 if ( ext === "gif" ) {
694695 if ( resizeCondition ) {
695- const { frameArray, delayArray} = await functions . getGIFFrames ( info . source )
696- const newFrameArray = [ ] as Buffer [ ]
697- for ( let i = 0 ; i < frameArray . length ; i ++ ) {
698- const newFrame = await sharp ( frameArray [ i ] )
699- . resize ( width , height , { fit : "fill" } )
700- . toBuffer ( )
701- newFrameArray . push ( newFrame )
696+ if ( process . platform === "win32" ) {
697+ const { frameArray, delayArray} = await functions . getGIFFrames ( info . source )
698+ const newFrameArray = [ ] as Buffer [ ]
699+ for ( let i = 0 ; i < frameArray . length ; i ++ ) {
700+ const newFrame = await sharp ( frameArray [ i ] )
701+ . resize ( width , height , { fit : "fill" } )
702+ . toBuffer ( )
703+ newFrameArray . push ( newFrame )
704+ }
705+ buffer = await functions . encodeGIF ( newFrameArray , delayArray , width , height )
706+ } else {
707+ buffer = await sharp ( buffer , { animated : true } ) . resize ( width , height , { fit : "fill" } ) . gif ( ) . toBuffer ( )
702708 }
703- buffer = await functions . encodeGIF ( newFrameArray , delayArray , width , height )
704709 if ( options . quality !== 100 ) {
705710 buffer = await imagemin . buffer ( buffer , { plugins : [
706711 imageminGifsicle ( { optimizationLevel : 3 } )
@@ -719,9 +724,11 @@ const compress = async (info: any) => {
719724 }
720725 if ( sourceExt !== ext ) {
721726 let s = sharp ( buffer , { animated : true } )
722- if ( ext === "jpg" || ext === "jpeg" ) s . jpeg ( )
723- if ( ext === "png" ) s . png ( )
724- if ( ext === "webp" ) s . webp ( )
727+ if ( ext === "jpg" || ext === "jpeg" ) s . jpeg ( { optimiseScans : options . progressive , quality : options . quality } )
728+ if ( ext === "png" ) s . png ( { quality : options . quality } )
729+ if ( ext === "webp" ) s . webp ( { quality : options . quality } )
730+ if ( ext === "avif" ) s . avif ( { quality : options . quality } )
731+ if ( ext === "jxl" ) s . jxl ( { quality : options . quality } )
725732 if ( ext === "gif" ) s . gif ( )
726733 buffer = await s . toBuffer ( )
727734 }
@@ -781,7 +788,8 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
781788 percentage : info . percentage ,
782789 keepRatio : info . keepRatio ,
783790 rename : info . rename ,
784- format : info . format
791+ format : info . format ,
792+ progressive : info . progressive
785793 }
786794 const fileSize = functions . parseFileSize ( info . fileSize )
787795 const ignoredSize = functions . parseFileSize ( options . ignoreBelow )
@@ -797,15 +805,19 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
797805 const resizeCondition = options . keepRatio ? ( options . percentage ? options . resizeWidth !== 100 : true ) : ( options . percentage ? ( options . resizeWidth !== 100 && options . resizeHeight !== 100 ) : true )
798806 if ( ext === "gif" ) {
799807 if ( resizeCondition ) {
800- const { frameArray, delayArray} = await functions . getGIFFrames ( info . source )
801- const newFrameArray = [ ] as Buffer [ ]
802- for ( let i = 0 ; i < frameArray . length ; i ++ ) {
803- const newFrame = await sharp ( frameArray [ i ] )
804- . resize ( width , height , { fit : "fill" } )
805- . toBuffer ( )
806- newFrameArray . push ( newFrame )
808+ if ( process . platform === "win32" ) {
809+ const { frameArray, delayArray} = await functions . getGIFFrames ( info . source )
810+ const newFrameArray = [ ] as Buffer [ ]
811+ for ( let i = 0 ; i < frameArray . length ; i ++ ) {
812+ const newFrame = await sharp ( frameArray [ i ] )
813+ . resize ( width , height , { fit : "fill" } )
814+ . toBuffer ( )
815+ newFrameArray . push ( newFrame )
816+ }
817+ buffer = await functions . encodeGIF ( newFrameArray , delayArray , width , height )
818+ } else {
819+ buffer = await sharp ( buffer , { animated : true } ) . resize ( width , height , { fit : "fill" } ) . gif ( ) . toBuffer ( )
807820 }
808- buffer = await functions . encodeGIF ( newFrameArray , delayArray , width , height )
809821 if ( options . quality !== 100 ) {
810822 buffer = await imagemin . buffer ( buffer , { plugins : [
811823 imageminGifsicle ( { optimizationLevel : 3 } )
@@ -824,9 +836,11 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
824836 }
825837 if ( sourceExt !== ext ) {
826838 let s = sharp ( buffer , { animated : true } )
827- if ( ext === "jpg" || ext === "jpeg" ) s . jpeg ( )
828- if ( ext === "png" ) s . png ( )
829- if ( ext === "webp" ) s . webp ( )
839+ if ( ext === "jpg" || ext === "jpeg" ) s . jpeg ( { optimiseScans : options . progressive , quality : options . quality } )
840+ if ( ext === "png" ) s . png ( { quality : options . quality } )
841+ if ( ext === "webp" ) s . webp ( { quality : options . quality } )
842+ if ( ext === "avif" ) s . avif ( { quality : options . quality } )
843+ if ( ext === "jxl" ) s . jxl ( { quality : options . quality } )
830844 if ( ext === "gif" ) s . gif ( )
831845 buffer = await s . toBuffer ( )
832846 }
@@ -839,7 +853,6 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
839853 ] } )
840854 }
841855 }
842- console . log ( buffer )
843856 return { buffer, fileSize : Buffer . byteLength ( buffer ) }
844857 } catch ( error ) {
845858 console . log ( error )
@@ -1011,7 +1024,7 @@ if (!singleLock) {
10111024 } )
10121025
10131026 app . on ( "ready" , ( ) => {
1014- window = new BrowserWindow ( { width : 800 , height : 600 , minWidth : 720 , minHeight : 450 , frame : false , backgroundColor : "#e14952" , center : true , webPreferences : { nodeIntegration : true , contextIsolation : false } } )
1027+ window = new BrowserWindow ( { roundedCorners : false , width : 800 , height : 600 , minWidth : 720 , minHeight : 450 , frame : false , backgroundColor : "#e14952" , center : true , webPreferences : { nodeIntegration : true , contextIsolation : false } } )
10151028 window . loadFile ( path . join ( __dirname , "index.html" ) )
10161029 window . removeMenu ( )
10171030 require ( "@electron/remote/main" ) . enable ( window . webContents )
0 commit comments