Registry / ai-ml / dhash
library1.4pypypi✓ verified 85d ago

A Python library for calculating difference hash (perceptual hash) for images, useful for detecting near-duplicates. Version 1.4 is stable but sees minimal maintenance; last updated in 2021. Release cadence is low.

pip install dhash
INSTALL
IMPORT
SIG · DHASH
D
dhash
ai-mlpythonv1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dhash
import dhash
from dhash import dhash
dhash is a module, not a function; use dhash.dhash_int() or dhash.dhash_row_col() after importing the module.

Loads an image and computes its 64-bit difference hash as an integer.

import dhash from PIL import Image image = Image.open('path/to/image.jpg') hash = dhash.dhash_int(image) print(format(hash, '016x')) # print as hex
Debug
Known issues
gotchaThe library expects a PIL Image object, not a file path. Always pass an opened image.
fix
Use Image.open(path) to get a PIL Image object before calling dhash.
affects: all
gotchaThe dhash_int() function returns an integer (64-bit hash), not a hex string. To display as hex, format it.
fix
Use format(hash, '016x') to get a hex string representation.
affects: all
deprecateddhash has no official support for Python versions older than 3.6, though it may still work. No new features are expected.
fix
Consider using imagehash library if active maintenance is desired.
affects: all
Errors
Common errors & fixes
AttributeError: module 'dhash' has no attribute 'dhash'
Incorrect import: trying to call dhash.dhash as a function, but the correct function is dhash_int.
fix
Use dhash.dhash_int(image) instead.
TypeError: expected str, bytes or os.PathLike object, not Image
Passing a PIL Image object to dhash functions that expect a file path (no, actually dhash expects Image). This error occurs when accidentally passing a filename string to dhash_int, which expects an already-opened Image.
fix
Open the image with Image.open() and pass that object.
Upgrade
Version history
1.4latest on PyPI · released Oct 23, 2022
Audit
Dependencies
PillowrequiredRequired for image loading and manipulation.
Agent activity
36 hits · last 30 days
node
32
Resources
dhash — pip install dhash · libregistry