commonsmachinery / blockhash-js

Image perceptual hash calculation in javascript
http://blockhash.io/
MIT License
172 stars 49 forks source link

Incorrect hashing of png #7

Open jonasob opened 9 years ago

jonasob commented 9 years ago

This image: https://commons.wikimedia.org/wiki/File:Arius.png

It's getting incorrectly hashed by blockhash-js, which gives a hash of 00ec008bbe80ffbf0000e9f9f8fb80fdffffffffffffffffffffffffffffffff instead of 0ff91ff10ff1000300018fd984d79ddf8e058fc30fc30fc3dfc3c3c303831783 as would be expected (from the C blockhash). The trailing fffff is a tell tale sign of an issue, which look very similar to the issue we had with jpeg where jpeg-js made assumptions about the image being RGB. Could something similar be amiss here?

chazzmoney commented 5 years ago

This is no longer an issue with the merge of #15, can you close?

artfwo commented 5 years ago

I'm still getting 00ec008bfe80ffbf0000f9f9f8fb80fdffffffffffffffffffffffffffffffff for the image above, the issue doesn't look fixed.

depsypher commented 5 years ago

Looks like this is caused by the png-js lib not handling indexed color images properly. I was able to fix it by switching to a different lib (https://github.com/lukeapage/pngjs):

https://github.com/commonsmachinery/blockhash-js/compare/master...depsypher:master

Not sure if you want a PR, because I couldn't get browserify to work with pngjs, but the existing tests pass as well as producing the correct hash for that Arius.png file.