| Crates.io | img_hash_linker |
| lib.rs | img_hash_linker |
| version | 1.1.0 |
| created_at | 2025-06-06 15:19:11.980399+00 |
| updated_at | 2025-06-16 17:28:12.378864+00 |
| description | A tool for opening links from images using perceptual hashing |
| homepage | |
| repository | https://github.com/TaylorHo/img-hash-linker |
| max_upload_size | |
| id | 1703185 |
| size | 64,867 |
A Rust library and CLI tool for linking images to URLs via perceptual hashing.
img_hash_linker computes perceptual image hashes (using the aHash algorithm) and associates them with URLs, allowing you to:
cargo install img_hash_linker
Add this to your Cargo.toml:
[dependencies]
img_hash_linker = "1.1.0"
The binary interface provides image hash computation and URL opening:
# Compute and display an image hash
img_hash_linker <image_path>
# Open a URL associated with an image
img_hash_linker <image_path> <csv_dict_path>
Where:
<image_path> is the path to the image file<csv_dict_path> is the path to a CSV file containing hash-URL pairs (example in example.csv)use img_hash_linker::{
compute_hash,
load_data_from_csv,
open_link_from_hash,
try_finding_similar_hash
};
let image_path = "path/to/image.jpg";
let dict_path = "path/to/links.csv";
// Configure hash size (optional, defaults to 8)
let hash_size: Option<u32> = Some(8); // Can also be None
// Compute hash from image
let hash: String = compute_hash(
image::open(image_path).unwrap(),
true, // remove white borders
hash_size // hash size configuration
).unwrap();
// Load hash-URL pairs from CSV
let links: Vec<(String, String)> = load_data_from_csv(dict_path).unwrap();
// Try to find exact match first
match open_link_from_hash(links.clone(), hash.clone()) {
Ok(message) => println!("{}", message), // Found exact match
Err(e) => {
// If no exact match, try finding similar hash
match try_finding_similar_hash(hash.clone(), links.clone(), None) {
Ok((similar_hash, _link, proximity)) => {
println!(
"{} (Proximity: {:.2}%)",
open_link_from_hash(links.clone(), similar_hash).unwrap(),
proximity * 100.0
);
}
Err(_) => {
println!("{}", e);
}
}
}
}
The CSV file should contain hash-URL pairs with headers:
hash,link
hash1,https://example.com/page1
hash2,https://example.com/page2
Important: The CSV must have hash and link headers. Additional fields are allowed but will be ignored.
Note: URLs can also be application URL handlers like spotify:// or vscode://.
The Average Hash (aHash) algorithm creates a perceptual hash of an image through these steps:
This creates a "fingerprint" of the image that: