Go implementation of multiple perceptual hash algorithms for images.
Full documentation lives on the wiki. It covers installation, a quick start guide, a per-algorithm reference (options, defaults, references, examples) for every hasher shipped with the library, an API reference for the Hasher / Comparer interfaces and the similarity distance functions, conceptual guides on hash types and interpolation methods, and practical guides for choosing an algorithm, comparing hashes, real-world examples, and migrating from v1 to v2.
go get -u github.com/ajdnik/imghash/v2import "github.com/ajdnik/imghash/v2"Most consumers only need the top-level imghash package. Core types (Hash, Binary, UInt8, Float64, Distance) are re-exported there.
If you're unsure which hash to pick, start with PDQ.
package main
import (
"fmt"
"github.com/ajdnik/imghash/v2"
)
func main() {
pdq, err := imghash.NewPDQ()
if err != nil {
panic(err)
}
h1, err := imghash.HashFile(pdq, "image1.png")
if err != nil {
panic(err)
}
h2, err := imghash.HashFile(pdq, "image2.png")
if err != nil {
panic(err)
}
dist, err := pdq.Compare(h1, h2)
if err != nil {
panic(err)
}
fmt.Printf("Distance: %v\n", dist)
}Imghash is released under the MIT license. See LICENSE.
