mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
🐛 修正放大图片
This commit is contained in:
parent
28fb788778
commit
211f0a667d
4
go.mod
4
go.mod
@ -3,9 +3,9 @@ module github.com/FloatTech/ZeroBot-Plugin
|
|||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220221142239-4b5244c3be4e
|
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220222045052-a7f28580c5d8
|
||||||
github.com/FloatTech/sqlite v0.2.0
|
github.com/FloatTech/sqlite v0.2.0
|
||||||
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220221142126-d6d123b013e2
|
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220221142658-9be64984adc5
|
||||||
github.com/antchfx/htmlquery v1.2.4
|
github.com/antchfx/htmlquery v1.2.4
|
||||||
github.com/corona10/goimagehash v1.0.3
|
github.com/corona10/goimagehash v1.0.3
|
||||||
github.com/fogleman/gg v1.3.0
|
github.com/fogleman/gg v1.3.0
|
||||||
|
|||||||
8
go.sum
8
go.sum
@ -1,10 +1,10 @@
|
|||||||
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220221142239-4b5244c3be4e h1:+eIhSEYF9fn/JNtnc4a3krXXDXp6Q0uewRxmDPL062s=
|
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220222045052-a7f28580c5d8 h1:549qKZCemMWO6iBg/3w0XwCeHL46HFsajtoCIvq6TSU=
|
||||||
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220221142239-4b5244c3be4e/go.mod h1:rq7SYTAJmt7tIt5k4SUgANFbQtZ6obEH50t89c9ip+8=
|
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220222045052-a7f28580c5d8/go.mod h1:KGZ/fb3ggu0YMeG/Pa1Ei2mtV1ebVdnvVW3gcUgBDQw=
|
||||||
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
|
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
|
||||||
github.com/FloatTech/sqlite v0.2.0 h1:x3uls/hExXH1+bbaNLkvilce6ATtWlDx4IqoxBW/bv8=
|
github.com/FloatTech/sqlite v0.2.0 h1:x3uls/hExXH1+bbaNLkvilce6ATtWlDx4IqoxBW/bv8=
|
||||||
github.com/FloatTech/sqlite v0.2.0/go.mod h1:xIDWIvpOFl8AXmZm0FC8t3PZjiR6ZutytCpBv2EWCns=
|
github.com/FloatTech/sqlite v0.2.0/go.mod h1:xIDWIvpOFl8AXmZm0FC8t3PZjiR6ZutytCpBv2EWCns=
|
||||||
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220221142126-d6d123b013e2 h1:E3k2HWTiJfmAM+bnTucvHZGeEEU/M88aFMfTGo+2wNQ=
|
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220221142658-9be64984adc5 h1:f1ZQ3Yvi92MqTKI0gqDlCqSHPUoEr5MFAKW8TB9wk9M=
|
||||||
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220221142126-d6d123b013e2/go.mod h1:lNDjXvvNHlo4LHiAMyP/FVWcvw6kWB5onuQ024QvHfw=
|
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220221142658-9be64984adc5/go.mod h1:lNDjXvvNHlo4LHiAMyP/FVWcvw6kWB5onuQ024QvHfw=
|
||||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
|
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=
|
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=
|
||||||
|
|||||||
@ -4,20 +4,31 @@ package scale
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"image"
|
"image"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/FloatTech/AnimeAPI/nsfw"
|
_ "image/gif" // import gif decoding
|
||||||
"github.com/FloatTech/AnimeAPI/scale"
|
_ "image/jpeg" // import jpg decoding
|
||||||
"github.com/FloatTech/zbputils/control"
|
_ "image/png" // import png decoding
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
_ "golang.org/x/image/webp" // import webp decoding
|
||||||
"github.com/FloatTech/zbputils/web"
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
|
"github.com/FloatTech/AnimeAPI/nsfw"
|
||||||
|
"github.com/FloatTech/AnimeAPI/scale"
|
||||||
|
|
||||||
|
"github.com/FloatTech/zbputils/binary"
|
||||||
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
|
"github.com/FloatTech/zbputils/img"
|
||||||
|
"github.com/FloatTech/zbputils/img/writer"
|
||||||
|
"github.com/FloatTech/zbputils/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -40,6 +51,7 @@ func init() {
|
|||||||
datachan <- d
|
datachan <- d
|
||||||
}()
|
}()
|
||||||
ctx.SendChain(message.Text("少女祈祷中..."))
|
ctx.SendChain(message.Text("少女祈祷中..."))
|
||||||
|
|
||||||
p, err := nsfw.Classify(url[0])
|
p, err := nsfw.Classify(url[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
@ -49,6 +61,7 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("请发送二次元图片!"))
|
ctx.SendChain(message.Text("请发送二次元图片!"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := <-datachan
|
data := <-datachan
|
||||||
if errsub != nil {
|
if errsub != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", errsub))
|
ctx.SendChain(message.Text("ERROR:", errsub))
|
||||||
@ -59,16 +72,31 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if im.Bounds().Size().X*im.Bounds().Size().Y > 512*512 {
|
px := im.Bounds().Size().X * im.Bounds().Size().Y
|
||||||
ctx.SendChain(message.Text("图片过大!"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
paras := ctx.State["scale_paras"].([2]int)
|
paras := ctx.State["scale_paras"].([2]int)
|
||||||
data, err = scale.Get(url[0], paras[0], paras[1], 2)
|
|
||||||
|
if px > 512*512 {
|
||||||
|
px = int(math.Pow(float64(px), 0.5) + 0.5)
|
||||||
|
x := im.Bounds().Size().X * px / 512
|
||||||
|
y := im.Bounds().Size().Y * px / 512
|
||||||
|
ctx.SendChain(message.Text("图片", im.Bounds().Size().X, "x", im.Bounds().Size().Y, "过大,调整图片至", x, "x", y))
|
||||||
|
im = img.Size(im, x, y).Im
|
||||||
|
w := binary.SelectWriter()
|
||||||
|
defer binary.PutWriter(w)
|
||||||
|
_, err = writer.WriteTo(im, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
data, err = scale.Post(bytes.NewReader(w.Bytes()), paras[0], paras[1], 2)
|
||||||
|
} else {
|
||||||
|
data, err = scale.Get(url[0], paras[0], paras[1], 2)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
n := cachedir + strconv.Itoa(int(ctx.Event.UserID))
|
n := cachedir + strconv.Itoa(int(ctx.Event.UserID))
|
||||||
f, err := os.Create(n)
|
f, err := os.Create(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user