@@ -194,7 +194,7 @@ func (a *App) SetModel(model string) {
194194 a .imgData .model = model
195195}
196196
197- func (a * App ) SaveImage (ImageType string ) error {
197+ func (a * App ) SaveImage (ImageType string , isJPG bool ) error {
198198 if ImageType == "RMBG" && a .imgData .rembgimg2 != nil {
199199 filePath , err := image .SaveImageDialog (a .ctx , false )
200200 if err != nil {
@@ -203,47 +203,53 @@ func (a *App) SaveImage(ImageType string) error {
203203 if filePath != "" {
204204 os .WriteFile (filePath , a .imgData .rembgimg2 , 0644 )
205205 }
206- } else if ImageType == "CROP" && a .imgData .pngcropimg != nil {
207- filePath , err := image .SaveImageDialog (a .ctx , false )
208- if err != nil {
209- return err
210- }
211- if filePath != "" {
212- os .WriteFile (filePath , a .imgData .pngcropimg , 0644 )
213- }
214- } else if ImageType == "CROP" && a .imgData .jpgcropimg != nil {
215- filePath , err := image .SaveImageDialog (a .ctx , true )
216- if err != nil {
217- return err
218- }
219- if filePath != "" {
220- os .WriteFile (filePath , a .imgData .jpgcropimg , 0644 )
221- }
222- } else if ImageType == "CROP" && a .imgData .pngcropimgpath != "" {
223- filePath , err := image .SaveImageDialog (a .ctx , false )
224- if err != nil {
225- return err
226- }
227- if filePath != "" {
228- imgBytes , err := image .ToBytesFromPath (a .imgData .pngcropimgpath )
229- if err != nil {
230- runtime .EventsEmit (a .ctx , "alert" , err .Error ())
231- return err
206+ } else if ImageType == "CROP" {
207+ if isJPG {
208+ if a .imgData .jpgcropimg != nil {
209+ filePath , err := image .SaveImageDialog (a .ctx , true )
210+ if err != nil {
211+ return err
212+ }
213+ if filePath != "" {
214+ os .WriteFile (filePath , a .imgData .jpgcropimg , 0644 )
215+ }
216+ } else if a .imgData .jpgcropimgpath != "" {
217+ imgBytes , err := image .ToBytesFromPath (a .imgData .jpgcropimgpath )
218+ if err != nil {
219+ runtime .EventsEmit (a .ctx , "alert" , err .Error ())
220+ return err
221+ }
222+ filePath , err := image .SaveImageDialog (a .ctx , true )
223+ if err != nil {
224+ return err
225+ }
226+ if filePath != "" {
227+ os .WriteFile (filePath , imgBytes , 0644 )
228+ }
232229 }
233- os .WriteFile (filePath , imgBytes , 0644 )
234- }
235- } else if ImageType == "CROP" && a .imgData .jpgcropimgpath != "" {
236- filePath , err := image .SaveImageDialog (a .ctx , true )
237- if err != nil {
238- return err
239- }
240- if filePath != "" {
241- imgBytes , err := image .ToBytesFromPath (a .imgData .jpgcropimgpath )
242- if err != nil {
243- runtime .EventsEmit (a .ctx , "alert" , err .Error ())
244- return err
230+ } else {
231+ if a .imgData .pngcropimg != nil {
232+ filePath , err := image .SaveImageDialog (a .ctx , false )
233+ if err != nil {
234+ return err
235+ }
236+ if filePath != "" {
237+ os .WriteFile (filePath , a .imgData .pngcropimg , 0644 )
238+ }
239+ } else if a .imgData .pngcropimgpath != "" {
240+ imgBytes , err := image .ToBytesFromPath (a .imgData .pngcropimgpath )
241+ if err != nil {
242+ runtime .EventsEmit (a .ctx , "alert" , err .Error ())
243+ return err
244+ }
245+ filePath , err := image .SaveImageDialog (a .ctx , false )
246+ if err != nil {
247+ return err
248+ }
249+ if filePath != "" {
250+ os .WriteFile (filePath , imgBytes , 0644 )
251+ }
245252 }
246- os .WriteFile (filePath , imgBytes , 0644 )
247253 }
248254 } else {
249255 runtime .EventsEmit (a .ctx , "alert" , "NO_IMAGE" )
@@ -253,27 +259,36 @@ func (a *App) SaveImage(ImageType string) error {
253259 return nil
254260}
255261
256- func (a * App ) CopyImage (ImageType string ) {
262+ func (a * App ) CopyImage (ImageType string , isJPG bool ) {
257263 if ImageType == "RMBG" && a .imgData .rembgimg2 != nil {
258264 image .CopyToClipboard (a .imgData .rembgimg2 , a .kernel32 , a .user32 , a .imgData .CF_PNG )
259- } else if ImageType == "CROP" && a .imgData .pngcropimg != nil {
260- image .CopyToClipboard (a .imgData .pngcropimg , a .kernel32 , a .user32 , a .imgData .CF_PNG )
261- } else if ImageType == "CROP" && a .imgData .jpgcropimg != nil {
262- image .CopyToClipboard (a .imgData .jpgcropimg , a .kernel32 , a .user32 , a .imgData .CF_PNG )
263- } else if ImageType == "CROP" && a .imgData .pngcropimgpath != "" {
264- imgBytes , err := image .ToBytesFromPath (a .imgData .pngcropimgpath )
265- if err != nil {
266- runtime .EventsEmit (a .ctx , "alert" , err .Error ())
267- return
268- }
269- image .CopyToClipboard (imgBytes , a .kernel32 , a .user32 , a .imgData .CF_PNG )
270- } else if ImageType == "CROP" && a .imgData .jpgcropimgpath != "" {
271- imgBytes , err := image .ToBytesFromPath (a .imgData .jpgcropimgpath )
272- if err != nil {
273- runtime .EventsEmit (a .ctx , "alert" , err .Error ())
274- return
265+ } else if ImageType == "CROP" {
266+ if isJPG {
267+ if a .imgData .jpgcropimg != nil {
268+ image .CopyToClipboard (a .imgData .jpgcropimg , a .kernel32 , a .user32 , a .imgData .CF_PNG )
269+ } else if a .imgData .jpgcropimgpath != "" {
270+ imgBytes , err := image .ToBytesFromPath (a .imgData .jpgcropimgpath )
271+ if err != nil {
272+ runtime .EventsEmit (a .ctx , "alert" , err .Error ())
273+ return
274+ }
275+ image .CopyToClipboard (imgBytes , a .kernel32 , a .user32 , a .imgData .CF_PNG )
276+ }
277+ } else {
278+ if a .imgData .pngcropimg != nil {
279+ image .CopyToClipboard (a .imgData .pngcropimg , a .kernel32 , a .user32 , a .imgData .CF_PNG )
280+ } else if a .imgData .pngcropimgpath != "" {
281+ imgBytes , err := image .ToBytesFromPath (a .imgData .pngcropimgpath )
282+ if err != nil {
283+ runtime .EventsEmit (a .ctx , "alert" , err .Error ())
284+ return
285+ }
286+ image .CopyToClipboard (imgBytes , a .kernel32 , a .user32 , a .imgData .CF_PNG )
287+ } else {
288+ runtime .EventsEmit (a .ctx , "alert" , "NO_IMAGE" )
289+ return
290+ }
275291 }
276- image .CopyToClipboard (imgBytes , a .kernel32 , a .user32 , a .imgData .CF_PNG )
277292 } else {
278293 runtime .EventsEmit (a .ctx , "alert" , "NO_IMAGE" )
279294 return
0 commit comments