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 InvaidBytesError::Base64(DecodeError::InvalidLength) if the string wasn’t valid base64. Otherwise returns the same errors as from_bytes`.