mirror of
https://github.com/fumiama/imago.git
synced 2026-06-13 05:31:10 +08:00
增加samediff
This commit is contained in:
@@ -14,8 +14,8 @@ Get hamming distance between two dhash strings
|
|||||||
Scan all images like 编码后哈希.webp
|
Scan all images like 编码后哈希.webp
|
||||||
### func Pick(exclude []string) string
|
### func Pick(exclude []string) string
|
||||||
Pick a random image
|
Pick a random image
|
||||||
### func Saveimgbytes(b []byte, imgdir string, uid string, force bool) (string, string)
|
### func Saveimgbytes(b []byte, imgdir string, uid string, force bool, samediff int) (string, string)
|
||||||
### func Saveimg(r io.Reader, imgdir string, uid string) (string, string)
|
### func Saveimg(r io.Reader, imgdir string, uid string, samediff int) (string, string)
|
||||||
Save image into imgdir with name like 编码后哈希.webp
|
Save image into imgdir with name like 编码后哈希.webp
|
||||||
Return value: status, dhash
|
Return value: status, dhash
|
||||||
### func Addimage(name string)
|
### func Addimage(name string)
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func Addimage(name string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Saveimgbytes Save image into imgdir with name like 编码后哈希.webp Return value: status, dhash
|
// Saveimgbytes Save image into imgdir with name like 编码后哈希.webp Return value: status, dhash
|
||||||
func Saveimgbytes(b []byte, imgdir string, uid string, force bool) (string, string) {
|
func Saveimgbytes(b []byte, imgdir string, uid string, force bool, samediff int) (string, string) {
|
||||||
r := bytes.NewReader(b)
|
r := bytes.NewReader(b)
|
||||||
img, _, err := image.Decode(r)
|
img, _, err := image.Decode(r)
|
||||||
iswebp := false
|
iswebp := false
|
||||||
@@ -95,7 +95,7 @@ func Saveimgbytes(b []byte, imgdir string, uid string, force bool) (string, stri
|
|||||||
} else {
|
} else {
|
||||||
for _, name := range images["sum"] {
|
for _, name := range images["sum"] {
|
||||||
diff, err := HammDistance(dh, name)
|
diff, err := HammDistance(dh, name)
|
||||||
if err == nil && diff < 10 { // 认为是一张图片
|
if err == nil && diff < samediff { // 认为是一张图片
|
||||||
log.Debugf("[saveimg] old %s.\n", name)
|
log.Debugf("[saveimg] old %s.\n", name)
|
||||||
return "\"stat\":\"exist\", \"img\": \"" + url.QueryEscape(name) + "\"", name
|
return "\"stat\":\"exist\", \"img\": \"" + url.QueryEscape(name) + "\"", name
|
||||||
}
|
}
|
||||||
@@ -127,10 +127,10 @@ func Saveimgbytes(b []byte, imgdir string, uid string, force bool) (string, stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Saveimg Save image into imgdir with name like 编码后哈希.webp Return value: status, dhash
|
// Saveimg Save image into imgdir with name like 编码后哈希.webp Return value: status, dhash
|
||||||
func Saveimg(r io.Reader, imgdir string, uid string) (string, string) {
|
func Saveimg(r io.Reader, imgdir string, uid string, samediff int) (string, string) {
|
||||||
imgbuff := make([]byte, 1024*1024) // 1m
|
imgbuff := make([]byte, 1024*1024) // 1m
|
||||||
r.Read(imgbuff)
|
r.Read(imgbuff)
|
||||||
return Saveimgbytes(imgbuff, imgdir, uid, false)
|
return Saveimgbytes(imgbuff, imgdir, uid, false, samediff)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scanimgs Scan all images like 编码后哈希.webp
|
// Scanimgs Scan all images like 编码后哈希.webp
|
||||||
|
|||||||
Reference in New Issue
Block a user