Skip to content
A Rust library for calculating perceptual hash values of images
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src fix panic in blockhash implementation Jun 28, 2018
.gitignore Add .idea/ to .gitignore Mar 13, 2017
.travis.yml Update to test on stable Jun 16, 2015
Cargo.toml widen `image` version range to `[0.10, 0.19]`, bump to 2.1.0 Jul 21, 2018
LICENSE-APACHE Migrate license to MIT/Apache-2.0 Mar 13, 2017

img_hash Build Status shield

Now builds on stable Rust! (But needs nightly to bench.)

A library for getting perceptual hash values of images.

Thanks to Dr. Neal Krawetz for the outlines of the Mean (aHash), Gradient (dHash), and DCT (pHash) perceptual hash algorithms: (Accessed August 2014)

Also provides an implementation of the algorithm.

With the rust-image feature, this crate can operate directly on buffers from the PistonDevelopers/image crate.



Add img_hash to your Cargo.toml:

version = "2.0"
# For interop with `image`:
features = ["rust-image"]

Example program:

extern crate image;
extern crate img_hash;

use std::path::Path;
use img_hash::{ImageHash, HashType};

fn main() {
    let image1 = image::open(&Path::new("image1.png")).unwrap();
    let image2 = image::open(&Path::new("image2.png")).unwrap();
    // These two lines produce hashes with 64 bits (8 ** 2),
    // using the Gradient hash, a good middle ground between 
    // the performance of Mean and the accuracy of DCT.
    let hash1 = ImageHash::hash(&image1, 8, HashType::Gradient);
    let hash2 = ImageHash::hash(&image2, 8, HashType::Gradient);
    println!("Image1 hash: {}", hash1.to_base64());
    println!("Image2 hash: {}", hash2.to_base64());
    println!("% Difference: {}", hash1.dist_ratio(&hash2));


In order to build and test on Rust stable, the benchmarks have to be placed behind a feature gate. If you have Rust nightly installed and want to run benchmarks, use the following command:

cargo bench --features bench


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

You can’t perform that action at this time.