dHash algorithm in Go
go get github.com/guilhermehn/dhash
Or with gopkg:
go get gopkg.in/guilhermehn/dhash.v1
Two parameters are needed: the path to the image and the size that the image will be resized to, that will reflect into the hash size. The recommended size is 8.
Dhash("image.jpg", 8)
The image will be resized to 8x8 and the hash
size will be size*2
: "8899aabbccddeeff"
.
package main
import (
"fmt"
"github.com/guilhermehn/dhash"
// or if you installed the gopkg version
// "gopkg.in/guilhermehn/dhash.v1"
)
func main() {
pathToImage := "path/to/image"
detailLevel := 8
hash, err := dhash.Dhash(pathToImage, detailLevel)
if err != nil {
fmt.Println("ERROR: %s", err.Error())
return
}
fmt.Println(hash)
}
MIT