From 761dde369375192a9ccafd0b575d6c09fdf3f67d Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sat, 10 May 2025 14:37:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=20LastDiffToImag?= =?UTF-8?q?e=20=E5=87=BD=E6=95=B0=EF=BC=8C=E5=8A=A8=E6=80=81=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E8=83=8C=E6=99=AF=E5=9B=BE=E5=A4=A7=E5=B0=8F=E4=BB=A5?= =?UTF-8?q?=E9=80=82=E5=BA=94=E5=A4=B4=E5=83=8F=E5=92=8C=E6=96=87=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E5=9B=BE=E5=83=8F=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/beatleader/model.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) 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) }