Struct image_hasher::ImageHash
source · pub struct ImageHash<B = Box<[u8]>> { /* private fields */ }
Expand description
A struct representing an image processed by a perceptual hash. For efficiency, does not retain a copy of the image data after hashing.
Get an instance with ImageHash::hash()
.
Implementations§
source§impl<B: HashBytes> ImageHash<B>
impl<B: HashBytes> ImageHash<B>
sourcepub fn from_bytes(bytes: &[u8]) -> Result<ImageHash<B>, InvalidBytesError>
pub fn from_bytes(bytes: &[u8]) -> Result<ImageHash<B>, InvalidBytesError>
Create an ImageHash
instance from the given bytes.
Errors:
Returns a InvalidBytesError::BytesWrongLength
error if the slice passed can’t fit in B
.
sourcepub fn dist(&self, other: &Self) -> u32
pub fn dist(&self, other: &Self) -> u32
Calculate the Hamming distance between this and other
.
Equivalent to counting the 1-bits of the XOR of the two hashes.
Essential to determining the perceived difference between self
and other
.
Note
This return value is meaningless if these two hashes are from different hash sizes or algorithms.
sourcepub fn from_base64(
encoded_hash: &str
) -> Result<ImageHash<B>, InvalidBytesError>
pub fn from_base64( encoded_hash: &str ) -> Result<ImageHash<B>, InvalidBytesError>
Create an ImageHash
instance from the given Base64-encoded string.
Errors:
Returns InvalidBytesError::Base64(DecodeError::InvalidLength)
if the string wasn’t valid base64.
Otherwise returns the same errors as from_bytes
.