{"action":"created","issue":{"url":"https://api.github.com/repos/JohannesBuchner/imagehash/issues/51","repository_url":"https://api.github.com/repos/JohannesBuchner/imagehash","labels_url":"https://api.github.com/repos/JohannesBuchner/imagehash/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/JohannesBuchner/imagehash/issues/51/comments","events_url":"https://api.github.com/repos/JohannesBuchner/imagehash/issues/51/events","html_url":"https://github.com/JohannesBuchner/imagehash/issues/51","id":209298578,"number":51,"title":"_binary_array_to_hex gives wrong value","user":{"login":"djunzu","id":8784122,"avatar_url":"https://avatars2.githubusercontent.com/u/8784122?v=4","gravatar_id":"","url":"https://api.github.com/users/djunzu","html_url":"https://github.com/djunzu","followers_url":"https://api.github.com/users/djunzu/followers","following_url":"https://api.github.com/users/djunzu/following{/other_user}","gists_url":"https://api.github.com/users/djunzu/gists{/gist_id}","starred_url":"https://api.github.com/users/djunzu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djunzu/subscriptions","organizations_url":"https://api.github.com/users/djunzu/orgs","repos_url":"https://api.github.com/users/djunzu/repos","events_url":"https://api.github.com/users/djunzu/events{/privacy}","received_events_url":"https://api.github.com/users/djunzu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-02-21T22:53:59Z","updated_at":"2017-10-27T16:52:54Z","closed_at":"2017-02-22T19:17:59Z","author_association":"NONE","body":"Correct me if I am wrong, but `_binary_array_to_hex` gives wrong values.\r\n\r\n```python\r\nPython 2.7.13 (default, Feb 16 2017, 19:11:00) \r\n[GCC 5.3.0] on linux2\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n>>> from PIL import Image\r\n>>> import imagehash\r\n>>> img = Image.open('sample_image.png')\r\n>>> ph = imagehash.phash(img)\r\n>>> bool_array = ph.hash.flatten()\r\n>>> bool_array\r\narray([ True, False, False,  True,  True,  True,  True, False, False,\r\n       False,  True,  True,  True,  True, False, False,  True,  True,\r\n       False, False, False, False, False,  True,  True,  True,  True,\r\n        True, False, False, False, False,  True,  True,  True,  True,\r\n       False, False, False, False,  True,  True, False, False, False,\r\n       False,  True,  True,  True,  True,  True, False, False,  True,\r\n        True,  True,  True,  True, False, False, False, False, False, False], dtype=bool)\r\n>>> bit_array = 1*bool_array\r\n>>> bit_array\r\narray([1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0,\r\n       1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,\r\n       1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0])\r\n>>> bit_string = ''.join(str(b) for b in bit_array)\r\n>>> bit_string\r\n'1001111000111100110000011111000011110000110000111110011111000000'\r\n>>> int(bit_string, 2)\r\n11402201597170935744L\r\n>>> hex(int(bit_string, 2))\r\n'0x9e3cc1f0f0c3e7c0L' # This is the expected hex value for the given bit array (phash)\r\n>>> str(ph)\r\n'793c830f0fc3e703' # and here is the actual value.\r\n```\r\n\r\nIf I made no mistake, let me know and I will submit a PR.\r\n"},"comment":{"url":"https://api.github.com/repos/JohannesBuchner/imagehash/issues/comments/340025655","html_url":"https://github.com/JohannesBuchner/imagehash/issues/51#issuecomment-340025655","issue_url":"https://api.github.com/repos/JohannesBuchner/imagehash/issues/51","id":340025655,"user":{"login":"JohannesBuchner","id":51015,"avatar_url":"https://avatars2.githubusercontent.com/u/51015?v=4","gravatar_id":"","url":"https://api.github.com/users/JohannesBuchner","html_url":"https://github.com/JohannesBuchner","followers_url":"https://api.github.com/users/JohannesBuchner/followers","following_url":"https://api.github.com/users/JohannesBuchner/following{/other_user}","gists_url":"https://api.github.com/users/JohannesBuchner/gists{/gist_id}","starred_url":"https://api.github.com/users/JohannesBuchner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohannesBuchner/subscriptions","organizations_url":"https://api.github.com/users/JohannesBuchner/orgs","repos_url":"https://api.github.com/users/JohannesBuchner/repos","events_url":"https://api.github.com/users/JohannesBuchner/events{/privacy}","received_events_url":"https://api.github.com/users/JohannesBuchner/received_events","type":"User","site_admin":false},"created_at":"2017-10-27T16:52:54Z","updated_at":"2017-10-27T16:52:54Z","author_association":"OWNER","body":"I think @djunzu established that this is about the encoding by byte order, namely that it is swapping byte pairs? I suspect that one can reproduce imagehash's implementation by reversing the byte sequence, transforming to hex and reversing that. \r\n\r\nI don't think there is a single \"correct\" solution for ordering the bytes from a 2d array into a hex string, any encoding is a choice. For accessing the bytes, the .hash attribute is the way to go. \r\nI fully expect that many users would implement their own encoding for their needs (e.g. storing in databases, etc.). Some may store the byte array directly, others a hex encoding, others may choose something that takes advantage of a larger alphabet characters. \r\n\r\nCould you explain some more why you need consistent encoding behaviour with other modules here, or you just stumbled across this oddity while making your own encoding? If you have a alternative and shorter string codec that does not introduce new dependencies, I would be interested.\r\n\r\n> Plus, the big vs little endian problem is about hardware and not about software/programing. \r\nThat's simply not true, see your references for network layers, file encoding, etc. "}}
{"actor":{"display_login":"JohannesBuchner"}}