1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

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
This commit is contained in:
源文雨 2022-01-15 18:37:26 +08:00 committed by GitHub
parent c000bf3596
commit 38bb31b5a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,12 +82,9 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*messag
return nil, errors.Wrap(err, "upload failed") return nil, errors.Wrap(err, "upload failed")
ok: ok:
_, _ = img.Seek(0, io.SeekStart) _, _ = img.Seek(0, io.SeekStart)
i, _, _ := imgsz.DecodeSize(img) i, t, _ := imgsz.DecodeSize(img)
var imageType int32 = 1000 var imageType int32 = 1000
_, _ = img.Seek(0, io.SeekStart) if t == "gif" {
tmp := make([]byte, 4)
_, _ = img.Read(tmp)
if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) {
imageType = 2000 imageType = 2000
} }
return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil 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") return nil, errors.Wrap(err, "upload failed")
ok: ok:
_, _ = img.Seek(0, io.SeekStart) _, _ = img.Seek(0, io.SeekStart)
i, _, _ := imgsz.DecodeSize(img) i, t, _ := imgsz.DecodeSize(img)
var imageType int32 = 1000 var imageType int32 = 1000
_, _ = img.Seek(0, io.SeekStart) if t == "gif" {
tmp := make([]byte, 4)
_, _ = img.Read(tmp)
if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) {
imageType = 2000 imageType = 2000
} }
return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil