From 38bb31b5a66607f4af0b0f86cd781a711c3c9b0e 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: Sat, 15 Jan 2022 18:37:26 +0800 Subject: [PATCH] feat(image): drop redundant bytewise comparing of gif (#243) * feat(image): drop rebundant bytewise comparing of gif * feat(image): drop redundant bytewise comparing of gif --- client/image.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/client/image.go b/client/image.go index 3e3ebb69..1ca5de55 100644 --- a/client/image.go +++ b/client/image.go @@ -82,12 +82,9 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*messag return nil, errors.Wrap(err, "upload failed") ok: _, _ = img.Seek(0, io.SeekStart) - i, _, _ := imgsz.DecodeSize(img) + i, t, _ := imgsz.DecodeSize(img) var imageType int32 = 1000 - _, _ = img.Seek(0, io.SeekStart) - tmp := make([]byte, 4) - _, _ = img.Read(tmp) - if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) { + if t == "gif" { imageType = 2000 } return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil @@ -135,12 +132,9 @@ func (c *QQClient) UploadGroupImageByFile(groupCode int64, path string) (*messag return nil, errors.Wrap(err, "upload failed") ok: _, _ = img.Seek(0, io.SeekStart) - i, _, _ := imgsz.DecodeSize(img) + i, t, _ := imgsz.DecodeSize(img) var imageType int32 = 1000 - _, _ = img.Seek(0, io.SeekStart) - tmp := make([]byte, 4) - _, _ = img.Read(tmp) - if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) { + if t == "gif" { imageType = 2000 } return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil