Skip to content

Commit c731556

Browse files
committed
Fixed bugs
1 parent a1bd61c commit c731556

File tree

3 files changed

+79
-64
lines changed

3 files changed

+79
-64
lines changed

app.go

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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

frontend/src/components/views/CropView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export function CropView() {
110110
<div style={{height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center'}}>
111111
<div style={{display: 'flex', flexDirection: 'column', gap: '10px', alignItems: 'center'}}>
112112
<div style={{height: '40px', display: 'flex', alignItems: 'center', justifyContent: 'center', width: '100%', gap: '10px'}}>
113-
<span style={{visibility: cropImage==""?'hidden':'visible'}}>PNG</span>
113+
<span style={{visibility: cropImage==""?'hidden':'visible', color: isDarkMode?'white':'black'}}>PNG</span>
114114
<Switch visibility={cropImage==""?'hidden':'visible'} primaryColor={accentColor} secondaryColor={accentColor} onChange={OnSwitchChange} value={isJPG}></Switch>
115-
<span style={{visibility: cropImage==""?'hidden':'visible'}}>JPEG</span>
115+
<span style={{visibility: cropImage==""?'hidden':'visible', color: isDarkMode?'white':'black'}}>JPEG</span>
116116
</div>
117117
<InputImageContainer></InputImageContainer>
118118
<div style={{display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', gap: '10px'}}>
@@ -130,10 +130,10 @@ export function CropView() {
130130
</Button>
131131
</div>
132132
<div style={{display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', gap: '10px'}}>
133-
<Button style={{width: '40px', height: '40px', visibility: cropImage==""?'hidden':'visible'}} onClick={() => CopyImage('CROP')} title={strings["CopyImage"]}>
133+
<Button style={{width: '40px', height: '40px', visibility: cropImage==""?'hidden':'visible'}} onClick={() => CopyImage('CROP', isJPG)} title={strings["CopyImage"]}>
134134
<FontAwesomeIcon icon={faCopy} size='xl'style={{transform: 'scale(0.8)'}} />
135135
</Button>
136-
<Button style={{width: '40px', height: '40px', visibility: cropImage==""?'hidden':'visible'}} onClick={() => SaveImage('CROP')} title={strings["SaveImage"]}>
136+
<Button style={{width: '40px', height: '40px', visibility: cropImage==""?'hidden':'visible'}} onClick={() => SaveImage('CROP', isJPG)} title={strings["SaveImage"]}>
137137
<FontAwesomeIcon icon={faCloudArrowDown} size='xl' style={{transform: 'scale(0.8)'}}/>
138138
</Button>
139139
</div>

frontend/src/components/views/RMBGView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ export function RMBGView() {
157157
<FontAwesomeIcon icon={faCropSimple} size='xl' style={{transform: 'scale(0.8)'}}/>
158158
</Button>
159159
<div style={{display: 'flex', flexDirection: 'row', gap: '10px'}}>
160-
<Button style={{width: '40px', height: '40px'}} onClick={() => CopyImage('RMBG')} title={strings["CopyImage"]}>
160+
<Button style={{width: '40px', height: '40px'}} onClick={() => CopyImage('RMBG', false)} title={strings["CopyImage"]}>
161161
<FontAwesomeIcon icon={faCopy} size='xl'style={{transform: 'scale(0.8)'}} />
162162
</Button>
163-
<Button style={{width: '40px', height: '40px'}} onClick={() => SaveImage('RMBG')} title={strings["SaveImage"]}>
163+
<Button style={{width: '40px', height: '40px'}} onClick={() => SaveImage('RMBG', false)} title={strings["SaveImage"]}>
164164
<FontAwesomeIcon icon={faCloudArrowDown} size='xl' style={{transform: 'scale(0.8)'}}/>
165165
</Button>
166166
</div>

0 commit comments

Comments
 (0)