Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@master
with:
go-version: 1.19
go-version: 1.24

- name: Check out code into the Go module directory
uses: actions/checkout@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@master
with:
go-version: 1.19
go-version: 1.24

- name: Check out code into the Go module directory
uses: actions/checkout@master
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ run:
tests: false
skip-dirs:
- order
go: '1.20'
go: '1.24'

# output configuration options
output:
Expand Down
12 changes: 8 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ func (t *Title) Sum64() uint64 {
type Alignment uint8

const (
NilAlign Alignment = iota // NilAlign ..
AlignLeft // AlignLeft 左对齐
AlignCenter // AlignCenter 居中对齐
AlignRight // AlignRight 右对齐
// NilAlign 默认
NilAlign Alignment = iota
// AlignLeft 左对齐
AlignLeft
// AlignCenter 居中对齐
AlignCenter
// AlignRight 右对齐
AlignRight
)

// Card 卡片配置
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/FloatTech/rendercard

go 1.20
go 1.24.2

require (
github.com/FloatTech/floatbox v0.0.0-20240505082030-226ec6713e14
Expand Down
17 changes: 17 additions & 0 deletions logo.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ func RenderServerListLogo(fontdata []byte) (img image.Image, err error) {
canvas.DrawImage(strokedimg, -3, 3)
canvas.DrawImage(coloredimg, 0, 0)

shadowcanvas := gg.NewContext(w, h)

err =shadowcanvas.SetMask(canvas.AsMask())
if err != nil {
return
}
shadowcanvas.DrawRectangle(0, 0, float64(shadowcanvas.W()), float64(shadowcanvas.H()))
shadowcanvas.SetRGBA255(0, 0, 0, 255)
shadowcanvas.Fill()

err =canvas.SetMask(canvas.AsMask())
if err != nil {
return
}
canvas.InvertMask()
canvas.DrawImage(shadowcanvas.Image(), 3, 4)

img = canvas.Image()
return
}
78 changes: 76 additions & 2 deletions serverpic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package rendercard

import (
"image"
"image/color"
"math/rand"
"sync"

"github.com/FloatTech/floatbox/math"
Expand Down Expand Up @@ -135,15 +137,63 @@ func renderinfocards(torussd, glowsd []byte, plugininfos []*PluginInfo) (img ima
beginw, beginh := 24.0, 0.0
for i := 0; i < cardnum; i++ {
canvas.SetRGBA255(204, 51, 51, 255)
if plugininfos[i].Status {
fade := gg.NewLinearGradient(beginw+10, 0, beginw+cardw-10, 0)
fade.AddColorStop(1, color.NRGBA{204, 51, 51, 255})
fade.AddColorStop(0.8, color.NRGBA{204, 51, 51, 191})
fade.AddColorStop(0.7, color.NRGBA{204, 51, 51, 63})
fade.AddColorStop(0.6, color.NRGBA{204, 51, 51, 0})
fade.AddColorStop(0, color.NRGBA{204, 51, 51, 0})
statusimage := drawEnableOrDisableImage(false)

if plugininfos[i].Status && rand.Intn(2) == 0 {
canvas.SetRGBA255(136, 178, 0, 255)
fade = gg.NewLinearGradient(beginw+10, 0, beginw+cardw-10, 0)
fade.AddColorStop(1, color.NRGBA{136, 178, 0, 255})
fade.AddColorStop(0.8, color.NRGBA{136, 178, 0, 191})
fade.AddColorStop(0.7, color.NRGBA{136, 178, 0, 63})
fade.AddColorStop(0.6, color.NRGBA{136, 178, 0, 0})
fade.AddColorStop(0, color.NRGBA{136, 178, 0, 0})
statusimage = drawEnableOrDisableImage(true)
}

canvas.DrawRoundedRectangle(beginw+10, beginh, cardw-10, cardh, 16)
canvas.Clip()
canvas.InvertMask()

canvas.DrawRoundedRectangle(beginw, beginh, cardw/2, cardh, 16)
canvas.Fill()

canvas.SetRGBA255(34, 26, 33, 255)
canvas.ResetClip()

canvas.SetRGBA255(255, 255, 255, 217)
canvas.DrawRoundedRectangle(beginw+10, beginh, cardw-10, cardh, 16)
canvas.FillPreserve()
canvas.SetFillStyle(fade)
canvas.Fill()
canvas.SetFillStyle(nil)

alphacanvas := gg.NewContext(w, h)
alphacanvas.SetRGBA255(255, 255, 255, 93)
alphacanvas.Clear()

err = canvas.SetMask(alphacanvas.AsMask())
if err != nil {
return
}
canvas.DrawImageAnchored(statusimage, int(beginw+cardw)-10-5, int(beginh+cardh/2), 1, 0.5)
canvas.ResetClip()

err = canvas.SetMask(alphacanvas.AsMask())
if err != nil {
return
}
canvas.DrawRoundedRectangle(beginw+10, beginh, cardw-10, cardh, 16)
canvas.Clip()
canvas.DrawCircle(beginw+cardw-10-5-50/2, beginh+cardh/2, float64(cardh-10)/2)
canvas.SetLineWidth(50 * 0.185)
canvas.Stroke()
canvas.ResetClip()

beginw += cardw + spacingw
if (i+1)%3 == 0 {
beginw = spacingw
Expand Down Expand Up @@ -181,3 +231,27 @@ func renderinfocards(torussd, glowsd []byte, plugininfos []*PluginInfo) (img ima
img = canvas.Image()
return
}

func drawEnableOrDisableImage(status bool) image.Image {
dc := gg.NewContext(50, 50)
dcwf, dchf := float64(dc.W()), float64(dc.H())
fac := 0.185
if status {
dc.RotateAbout(gg.Radians(-45), dcwf/2, dchf/2)
dc.DrawRectangle(dcwf*fac+dcwf*fac/2, (dchf-dchf/2)/2-1, dcwf, dcwf/2-dcwf*fac)
dc.Clip()
dc.InvertMask()
dc.DrawRectangle(dcwf*fac/2, (dchf-dchf/2)/2, dcwf-dcwf*fac, dchf/2)
dc.SetRGBA255(255, 255, 255, 255)
dc.Fill()
dc.ResetClip()
return dc.Image()
}
dc.RotateAbout(gg.Radians(-45), dcwf/2, dchf/2)
dc.DrawRectangle((dcwf-dcwf*fac)/2, 0, dcwf*fac, dchf)
dc.SetRGBA255(255, 255, 255, 255)
dc.Fill()
dc.DrawRectangle(0, (dcwf-dcwf*fac)/2, dchf, dcwf*fac)
dc.Fill()
return dc.Image()
}
Loading