From e5efa191afc140b79166d6dff3ce8f1906e62576 Mon Sep 17 00:00:00 2001 From: fumiama Date: Tue, 10 Aug 2021 18:52:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3uid=E4=B8=8Esave=20add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- storage.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5b03333..4ba4f9e 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ Get hamming distance between two dhash strings Scan all images like 编码后哈希.webp ### func Pick(exclude []string) string Pick a random image -### func Saveimgbytes(b []byte, imgdir string, uid string, force bool, samediff int) (string, string) -### func Saveimg(r io.Reader, imgdir string, uid string, samediff int) (string, string) +### func Saveimgbytes(b []byte, imgdir string, force bool, samediff int) (string, string) +### func Saveimg(r io.Reader, imgdir string, samediff int) (string, string) Save image into imgdir with name like 编码后哈希.webp Return value: status, dhash ### func Addimage(name string) diff --git a/storage.go b/storage.go index 5072546..9537f12 100644 --- a/storage.go +++ b/storage.go @@ -70,7 +70,7 @@ func Addimage(name string) { } // Saveimgbytes Save image into imgdir with name like 编码后哈希.webp Return value: status, dhash -func Saveimgbytes(b []byte, imgdir string, uid string, force bool, samediff int) (string, string) { +func Saveimgbytes(b []byte, imgdir string, force bool, samediff int) (string, string) { r := bytes.NewReader(b) img, _, err := image.Decode(r) iswebp := false @@ -125,14 +125,15 @@ func Saveimgbytes(b []byte, imgdir string, uid string, force bool, samediff int) log.Debugf("[saveimg] save %d bytes.\n", c) } log.Debugf("[saveimg] new %s.\n", dh) + Addimage(dh) return "\"stat\":\"success\", \"img\": \"" + url.QueryEscape(dh) + "\"", dh } // Saveimg Save image into imgdir with name like 编码后哈希.webp Return value: status, dhash -func Saveimg(r io.Reader, imgdir string, uid string, samediff int) (string, string) { +func Saveimg(r io.Reader, imgdir string, samediff int) (string, string) { imgbuff := make([]byte, 1024*1024) // 1m r.Read(imgbuff) - return Saveimgbytes(imgbuff, imgdir, uid, false, samediff) + return Saveimgbytes(imgbuff, imgdir, false, samediff) } // Scanimgs Scan all images like 编码后哈希.webp