benhoyt/dhash

the type of return value of dhash.format_hex() is str

BBge opened this issue · 4 comments

BBge commented

the type of return value of dhash.format_hex() is str, maybe you can change the type of return value to hex. And the users needn't to convert it when they use dhash.get_num_bits_different().

This is screwing me over. I'm finding no way to use get_num_bits with any form of variable that converts it to a hex number. With all the excuses in the book, no str, no int even when it's hex.
Only way is to manually enter hex numbers, and then this is rendered useless.

Sorry, but I'm not really sure what you're asking. Most functions that convert to hex return a str in Python, for example the built-in hex() function. There's no such thing as a "hex type", at least not in the standard library.

If you want to use get_num_bits_different(), first call dhash_int() on both images (this returns an integer), then pass the results of those to get_num_bits_different(). For example, see here: https://github.com/Jetsetter/dhash/blob/master/dhash.py#L281-L283

image1 = Image.open('image_name.jpg')
hash1 = dhash_int(image1)

Traceback (most recent call last):
File "*", line 105, in
hash1 = dhash_int(image1)
NameError: name 'dhash_int' is not defined

How are you importing dhash? If you're using import dhash then you'll have to type dhash.dhash_int() Otherwise you can do from dhash import dhash_int and then use it directly.