-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module github.com/FloatTech/rendercard | ||
|
||
go 1.19 | ||
|
||
require github.com/Coloured-glaze/gg v1.3.4 | ||
|
||
require ( | ||
github.com/disintegration/imaging v1.6.2 // indirect | ||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect | ||
github.com/fogleman/gg v1.3.0 // indirect | ||
github.com/wdvxdr1123/ZeroBot v1.6.3 // indirect | ||
golang.org/x/text v0.4.0 // indirect | ||
) | ||
|
||
require ( | ||
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57 | ||
github.com/FloatTech/zbputils v1.5.0 | ||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect | ||
golang.org/x/image v0.1.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
github.com/Coloured-glaze/gg v1.3.4 h1:l31zIF/HaVwkzjrj+A56RGQoSKyKuR1IWtIrqXGFStI= | ||
github.com/Coloured-glaze/gg v1.3.4/go.mod h1:Ih5NLNNDHOy3RJbB0EPqGTreIzq/H02TGThIagh8HJg= | ||
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57 h1:1H1QSxBPqq7o4S5/xtl0cI/GOqaiajoBg+156cuK1e4= | ||
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57/go.mod h1:72tI2fKLhrNpuj4AlE2HSjJOAtEnUEKOx/+dEYSc4FE= | ||
github.com/FloatTech/zbputils v1.5.0 h1:mfKZ+Ye+t8eArmgR4PzhhmdwvZM5VPjLfdikyhKffSE= | ||
github.com/FloatTech/zbputils v1.5.0/go.mod h1:Qet1L7sDLCkYectR0cwtTA9yDcW1n4/U1JvnAq2X18A= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= | ||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= | ||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 h1:BBade+JlV/f7JstZ4pitd4tHhpN+w+6I+LyOS7B4fyU= | ||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4/go.mod h1:H7chHJglrhPPzetLdzBleF8d22WYOv7UM/lEKYiwlKM= | ||
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= | ||
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= | ||
github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo= | ||
github.com/fumiama/cron v1.3.0/go.mod h1:bz5Izvgi/xEUI8tlBN8BI2jr9Moo8N4or0KV8xXuPDY= | ||
github.com/fumiama/go-base16384 v1.6.1 h1:4yb4JgmBJDnQtq3XGXXdLrVwEnRpjhMUt4eAcsNeA30= | ||
github.com/fumiama/go-base16384 v1.6.1/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM= | ||
github.com/fumiama/go-registry v0.1.6 h1:Ee/tXCCIR/xt8celhbbw0W/xDMdhAXLwy2YFBB/LWFk= | ||
github.com/fumiama/go-registry v0.1.6/go.mod h1:dIUVbiOgfk9oZcsgwDvNLC72i+ctibVukSXR/9bLviI= | ||
github.com/fumiama/go-registry v0.2.2 h1:BAA/pltg/Ryq3oj4CRJBenVZM6EowOQvtHbv/rPp2LY= | ||
github.com/fumiama/go-registry v0.2.2/go.mod h1:GP45kejHuDLFxcWdksrt75r5rHBqYwtfeUl3JzGWxfQ= | ||
github.com/fumiama/go-simple-protobuf v0.1.0 h1:rLzJgNqB6LHNDVMl81yyNt6ZKziWtVfu+ioF0edlEVw= | ||
github.com/fumiama/go-simple-protobuf v0.1.0/go.mod h1:5yYNapXq1tQMOZg9bOIVhQlZk9pQqpuFIO4DZLbsdy4= | ||
github.com/fumiama/gofastTEA v0.0.10 h1:JJJ+brWD4kie+mmK2TkspDXKzqq0IjXm89aGYfoGhhQ= | ||
github.com/fumiama/gofastTEA v0.0.10/go.mod h1:RIdbYZyB4MbH6ZBlPymRaXn3cD6SedlCu5W/HHfMPBk= | ||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= | ||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= | ||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/wdvxdr1123/ZeroBot v1.5.2-0.20220715040337-ef4327320c40 h1:j+cmfkjc8WcBKiOsvMzcIgAuPhiTs7FBeiRn/QLVFhA= | ||
github.com/wdvxdr1123/ZeroBot v1.5.2-0.20220715040337-ef4327320c40/go.mod h1:LJ+VOf523i3IrykuLK53UEeWqnAclRL5d2wGT4sS4Zk= | ||
github.com/wdvxdr1123/ZeroBot v1.6.3 h1:Xf+rM8fR9Etc7ydcGHuqCk0ulAAn7Oa7nD9Zy/qZ6Pk= | ||
github.com/wdvxdr1123/ZeroBot v1.6.3/go.mod h1:shG/ruauisKaVcov4amrFJtkeDl7nl+Q00IXB2PqFsc= | ||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||
golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk= | ||
golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c= | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | ||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 h1:9vYwv7OjYaky/tlAeD7C4oC9EsPTlaFl1H2jS++V+ME= | ||
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc= | ||
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= | ||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
// Package rendercard ... | ||
package rendercard | ||
|
||
import ( | ||
"image" | ||
"math/rand" | ||
"strconv" | ||
|
||
"github.com/Coloured-glaze/gg" | ||
"github.com/FloatTech/floatbox/img/writer" | ||
"github.com/FloatTech/zbputils/img" | ||
) | ||
|
||
const ( | ||
Imgwight = 1272.0 | ||
) | ||
|
||
// Titleinfo ... | ||
type Titleinfo struct { | ||
Lefttitle string | ||
Leftsubtitle string | ||
|
||
Righttitle string | ||
Rightsubtitle string | ||
|
||
Imgpath string | ||
|
||
Textpath string | ||
Textpath2 string | ||
|
||
Status bool | ||
} | ||
|
||
// Drawtitle ... | ||
func (t Titleinfo) Drawtitle() (imgs image.Image, err error) { | ||
// 创建图像 | ||
canvas := gg.NewContext(int(Imgwight), 30+30+300+(9*(256+30))) | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
canvas.Clear() | ||
|
||
// 标题背景1 | ||
canvas.DrawRectangle(0, 30, Imgwight, 300) | ||
canvas.SetRGBA255(0, 0, 0, 153) | ||
canvas.Fill() | ||
|
||
// 标题背景2 | ||
canvas.DrawRectangle(0, 30+40, Imgwight, 220) | ||
canvas.SetRGBA255(0, 0, 0, 153) | ||
canvas.Fill() | ||
|
||
// 加载size为108的字体 | ||
err = canvas.LoadFontFace(t.Textpath, 108) | ||
if err != nil { | ||
return | ||
} | ||
|
||
// 绘制标题 | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
canvas.DrawString(t.Lefttitle, 25, 30+40+55+canvas.FontHeight()-canvas.FontHeight()/3) | ||
|
||
// 加载size为54的字体 | ||
err = canvas.LoadFontFace(t.Textpath, 54) | ||
if err != nil { | ||
return | ||
} | ||
|
||
// 绘制一系列标题 | ||
canvas.DrawString(t.Leftsubtitle, 25+3, 30+40+165+canvas.FontHeight()/3) | ||
|
||
fw, _ := canvas.MeasureString(t.Righttitle) | ||
canvas.DrawString(t.Righttitle, Imgwight-25-fw-170-25, 30+40+25+15+canvas.FontHeight()+canvas.FontHeight()/4) | ||
fw1, _ := canvas.MeasureString(t.Rightsubtitle) | ||
canvas.DrawString(t.Rightsubtitle, Imgwight-25-fw1-170-25, 30+40+25+15+canvas.FontHeight()*2+canvas.FontHeight()/2) | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
|
||
// 加载icon并绘制 | ||
var icon *img.Factory | ||
icon, err = img.LoadFirstFrame(t.Imgpath, 170, 170) | ||
if err != nil { | ||
return | ||
} | ||
canvas.DrawImage(icon.Im, int(Imgwight)-25-170, 30+40+25) | ||
imgs = canvas.Image() | ||
return | ||
} | ||
|
||
// Drawtitledtext ... | ||
func (t Titleinfo) Drawtitledtext(info []string) (imgs []byte, err error) { | ||
|
||
imgh := len(info)*(38+20) + 220 + 10 + 30 + 10 + 50 | ||
|
||
// 创建图像 | ||
canvas := gg.NewContext(int(Imgwight), imgh) | ||
canvas.SetRGBA255(15, 15, 15, 204) | ||
canvas.Clear() | ||
|
||
// 加载icon | ||
var icon *img.Factory | ||
icon, err = img.LoadFirstFrame(t.Imgpath, 170, 170) | ||
if err != nil { | ||
return | ||
} | ||
canvas.DrawImage(icon.Im, int(Imgwight)-25-170, 25) | ||
|
||
// 绘制标题与内容的分割线 | ||
canvas.DrawRectangle(0, 220, Imgwight, 10) | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
canvas.Fill() | ||
|
||
// 加载size为108的字体 | ||
err = canvas.LoadFontFace(t.Textpath, 108) | ||
if err != nil { | ||
return | ||
} | ||
|
||
// 绘制标题 | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
canvas.DrawString(t.Lefttitle, 25+40+25, 55+canvas.FontHeight()-canvas.FontHeight()/3) | ||
|
||
// 加载size为54的字体 | ||
err = canvas.LoadFontFace(t.Textpath, 54) | ||
if err != nil { | ||
return | ||
} | ||
|
||
// 绘制插件开启状态 | ||
canvas.DrawRectangle(25, 25, 40, 170) | ||
if t.Status { | ||
canvas.SetRGBA255(15, 175, 15, 255) | ||
} else { | ||
canvas.SetRGBA255(200, 15, 15, 255) | ||
} | ||
canvas.Fill() | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
|
||
// 绘制一系列标题 | ||
canvas.DrawString(t.Leftsubtitle, 25+3+40+25, 165+canvas.FontHeight()/3) | ||
fw, _ := canvas.MeasureString(t.Righttitle) | ||
canvas.DrawString(t.Righttitle, Imgwight-25-fw-170-25, 25+15+canvas.FontHeight()+canvas.FontHeight()/4) | ||
fw1, _ := canvas.MeasureString(t.Rightsubtitle) | ||
canvas.DrawString(t.Rightsubtitle, Imgwight-25-fw1-170-25, 25+15+canvas.FontHeight()*2+canvas.FontHeight()/2) | ||
|
||
// 加载size为38的字体 | ||
err = canvas.LoadFontFace(t.Textpath2, 38) | ||
if err != nil { | ||
return | ||
} | ||
|
||
x, y := 25.0, 25.0 | ||
for i := 0; i < len(info); i++ { | ||
canvas.DrawString(info[i], x, y+220+10+canvas.FontHeight()) | ||
y += 20 + canvas.FontHeight() | ||
} | ||
imgs, cl := writer.ToBytes(canvas.Image()) | ||
cl() | ||
return | ||
} | ||
|
||
// Drawcard ... | ||
func (t Titleinfo) Drawcard() (imgs image.Image, err error) { | ||
recw, rech := 384.0, 256.0 | ||
canvas := gg.NewContext(int(recw), int(rech)) | ||
// 绘制图片 | ||
var banner *img.Factory | ||
banner, err = img.LoadFirstFrame(t.Imgpath, int(recw)*2, int(rech)*2) | ||
if err == nil { | ||
canvas.DrawImage(img.Size(banner.Im, int(recw), int(rech)).Im, 0, 0) | ||
} else { | ||
canvas.DrawRectangle(0, 0, recw, rech) | ||
canvas.SetRGBA255(rand.Intn(45)+165, rand.Intn(45)+165, rand.Intn(45)+165, 255) | ||
canvas.Fill() | ||
} | ||
|
||
// 绘制遮罩 | ||
canvas.DrawRectangle(0, rech/3*2, recw, rech/3) | ||
canvas.SetRGBA255(0, 0, 0, 153) | ||
canvas.Fill() | ||
|
||
// 绘制排名 | ||
canvas.DrawRectangle(recw/10, 0, recw/10, (rech/4)-10) | ||
canvas.DrawRoundedRectangle(recw/10, 0, recw/10, (rech / 4), 8) | ||
if t.Status { | ||
canvas.SetRGBA255(15, 175, 15, 255) | ||
} else { | ||
canvas.SetRGBA255(200, 15, 15, 255) | ||
} | ||
canvas.Fill() | ||
|
||
// 绘制插件排名 | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
var fw2 float64 | ||
i, _ := strconv.Atoi(t.Rightsubtitle) | ||
if i > 99 { | ||
err = canvas.LoadFontFace(t.Textpath, 24) | ||
} else { | ||
err = canvas.LoadFontFace(t.Textpath, 28) | ||
} | ||
if err != nil { | ||
return | ||
} | ||
fw2, _ = canvas.MeasureString(t.Rightsubtitle) | ||
canvas.DrawString(t.Rightsubtitle, recw/10+((recw/10-fw2)/2), canvas.FontHeight()*3/8+(rech/8)) | ||
|
||
// 绘制插件信息 | ||
canvas.SetRGBA255(240, 240, 240, 255) | ||
err = canvas.LoadFontFace(t.Textpath, 48) | ||
if err != nil { | ||
return | ||
} | ||
canvas.DrawString(t.Lefttitle, recw/32, (recw*0.475)+canvas.FontHeight()-canvas.FontHeight()/4) | ||
|
||
err = canvas.LoadFontFace(t.Textpath, 24) | ||
if err != nil { | ||
return | ||
} | ||
canvas.DrawString(t.Leftsubtitle, recw/32, (recw*0.475)+recw/6-canvas.FontHeight()/4) | ||
|
||
imgs = canvas.Image() | ||
return | ||
} |