Skip to content

Commit

Permalink
update:修改score抽取本地图片逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
vatebur committed Nov 27, 2024
1 parent 51e1884 commit bfb0eec
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions plugin/score/sign_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,21 @@ func copyImage(picFile string) (err error) {
if err != nil {
return err
}
// 筛选图片
var validFiles []string
for _, imgName := range files {
if !imgName.IsDir() && strings.HasSuffix(imgName.Name(), ".png") && !strings.HasSuffix(imgName.Name(), "signin.png") {
validFiles = append(validFiles, imgName.Name())

// 随机取10次图片,取到图片就break退出
imgNum := len(files)
var validFile string
for i := 0; i < len(files) && i < 10; i++ {
imgFile := files[rand.Intn(imgNum)]
if !imgFile.IsDir() && strings.HasSuffix(imgFile.Name(), ".png") && !strings.HasSuffix(imgFile.Name(), "signin.png") {
validFile = imgFile.Name()
break
}
}
if len(validFiles) == 0 {
return errors.New("copyImage: no valid ia found")
if len(validFile) == 0 {
return errors.New("copyImage: no local image")
}
selectedFile := cachePath + validFiles[rand.Intn(len(validFiles))]
selectedFile := cachePath + validFile

// 使用 io.Copy 复制签到背景
srcFile, err := os.Open(selectedFile)
Expand All @@ -409,5 +413,5 @@ func copyImage(picFile string) (err error) {
return err
}

return nil
return err
}

0 comments on commit bfb0eec

Please sign in to comment.