Installation
Get started with imghash in your Go project with a single command.Requirements
imghash requires Go 1.25 or later. Check your version with
go version.golang.org/x/image- Extended image format support
Install with go get
Install the package
Run the following command in your project directory:This downloads the latest version of imghash v2 and adds it to your
go.mod file.Import the package
Add the import to your Go source files:Most consumers only need the top-level
imghash package. Core types (Hash, Binary, UInt8, Float64, Distance) are re-exported there.Package Structure
imghash is organized into several packages:Top-Level Package
The mainimghash package exports all algorithms and core types:
Subpackages (Advanced Usage)
For advanced use cases, you can import specific subpackages:Most users won’t need to import subpackages. The main
imghash package re-exports everything you need.Supported Image Formats
imghash automatically registers decoders for common image formats:- JPEG -
.jpg,.jpeg - PNG -
.png - GIF -
.gif
imghash/convenience.go:5-7
Adding More Formats
To support additional formats like WebP or TIFF, import their decoders:Module Configuration
Yourgo.mod file should include:
golang.org/x/image will be added automatically:
Version Pinning
To use a specific version:Troubleshooting
Error: package github.com/ajdnik/imghash/v2 is not in GOROOT
Error: package github.com/ajdnik/imghash/v2 is not in GOROOT
This means the package isn’t downloaded. Run:
Error: unknown revision v2
Error: unknown revision v2
Make sure you’re using
/v2 in the import path for version 2:Error: unsupported image format
Error: unsupported image format
The image format isn’t registered. Add the appropriate decoder import:
Go version too old
Go version too old
imghash v2 requires Go 1.25+. Upgrade Go or use an older version of imghash: