diff --git a/service/beatleader/model.go b/service/beatleader/model.go index 58e0c97..765fc84 100644 --- a/service/beatleader/model.go +++ b/service/beatleader/model.go @@ -6,6 +6,7 @@ import ( "image/color" "image/draw" "log" + "math" "os" "strings" "time" @@ -542,14 +543,7 @@ func (p PlayerDataLite) LastDiffToImage(lastDayQueryData PlayerDataLite) string // } baseboard := sprite.NewNamedSpriteBoard() - background := image.NewRGBA(image.Rect(0, 0, 500, 1000)) - draw.Draw(background, background.Bounds(), image.White, image.Point{}, draw.Src) - backgroundSpirit := sprite.Sprite{ - Name: "background", - Image: background, - Index: 0, - } - baseboard.AddSprite(&backgroundSpirit) + avatar, err := util.ResizeImageByMaxHeight2Image(filePath, 20) if err != nil { log.Default().Printf("缩放头像失败,url:%s,err:%v", p.Avatar, err) @@ -621,10 +615,22 @@ func (p PlayerDataLite) LastDiffToImage(lastDayQueryData PlayerDataLite) string Name: "text", Image: textImg, Index: 2, - Position: image.Point{X: 23, Y: 23}, + Position: image.Point{X: 23, Y: 0}, } baseboard.AddSprite(&textSpirit) + totalWidth := textImg.Bounds().Dx() + avatar.Bounds().Dx() + totalHeight := math.Max(float64(textImg.Bounds().Dy()), float64(avatar.Bounds().Dy())) + + background := image.NewRGBA(image.Rect(0, 0, int(totalWidth), int(totalHeight))) + draw.Draw(background, background.Bounds(), image.White, image.Point{}, draw.Src) + backgroundSpirit := sprite.Sprite{ + Name: "background", + Image: background, + Index: 0, + } + baseboard.AddSprite(&backgroundSpirit) + if err := baseboard.SaveToPng(util.GenTempFilePath("cbl.png")); err != nil { log.Default().Printf("保存图片失败,err:%v", err) }