From a5670ccc4348b7bb7b483138b121388273521c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 14 Jan 2022 20:21:06 +0800 Subject: [PATCH] feat: use the decoder which only parses size info (#238) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add GroupImage Width & Height for webp * fix: 简化写法 * feat: use imgsz package and drop image --- client/image.go | 6 +++--- go.mod | 1 + go.sum | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/image.go b/client/image.go index e3736b9f..3e3ebb69 100644 --- a/client/image.go +++ b/client/image.go @@ -3,13 +3,13 @@ package client import ( "bytes" "encoding/hex" - "image" "io" "math/rand" "os" "strings" "time" + "github.com/fumiama/imgsz" "github.com/pkg/errors" "github.com/Mrs4s/MiraiGo/binary" @@ -82,7 +82,7 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*messag return nil, errors.Wrap(err, "upload failed") ok: _, _ = img.Seek(0, io.SeekStart) - i, _, _ := image.DecodeConfig(img) + i, _, _ := imgsz.DecodeSize(img) var imageType int32 = 1000 _, _ = img.Seek(0, io.SeekStart) tmp := make([]byte, 4) @@ -135,7 +135,7 @@ func (c *QQClient) UploadGroupImageByFile(groupCode int64, path string) (*messag return nil, errors.Wrap(err, "upload failed") ok: _, _ = img.Seek(0, io.SeekStart) - i, _, _ := image.DecodeConfig(img) + i, _, _ := imgsz.DecodeSize(img) var imageType int32 = 1000 _, _ = img.Seek(0, io.SeekStart) tmp := make([]byte, 4) diff --git a/go.mod b/go.mod index c676ed7f..83b7f008 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.17 require ( github.com/RomiChan/protobuf v0.0.0-20211223055824-048df49a8956 + github.com/fumiama/imgsz v0.0.2 github.com/klauspost/compress v1.13.6 github.com/pierrec/lz4/v4 v4.1.11 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 78856e76..5c9e6c29 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/RomiChan/protobuf v0.0.0-20211223055824-048df49a8956/go.mod h1:CKKOWC github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fumiama/imgsz v0.0.2 h1:fAkC0FnIscdKOXwAxlyw3EUba5NzxZdSxGaq3Uyfxak= +github.com/fumiama/imgsz v0.0.2/go.mod h1:dR71mI3I2O5u6+PCpd47M9TZptzP+39tRBcbdIkoqM4= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=