Open yaneony opened 7 years ago
What is your code/offending line?
What do you mean?
I have same problem. I don't know why but you can reproduce it in Codesandbox below. https://codesandbox.io/s/loving-ride-eiljq?file=/src/index.js
In short, the distance between two different images will be zero.
Jimp.distance(image1, image2) === 0
These are sample images. You can download:
image1 image2
@teramotodaiki did you manage to find a workaround for this issue?
I'm experiencing the same issue with two completely different .png images, still the hash() function is returning the same "80000000000" hash.
I tried converting the two images to .jpg but obtained the same results.
Jimp.read('l3qn22kjlm.png', (err, res) => { console.log(res.hash())} );
Jimp.read('lcjb3u6c27.png', (err, res) => { console.log(res.hash())} );
//output
80000000000
80000000000
I'm currently using jimp package without any issues except for this one, so I'm guessing it has something to do with these specific images:
Thanks in advance to all the kind souls willing to help :)
If anyone wants to submit a PR to fix I'm able to review and merge!
So I really don't know what I'm doing when it comes to phash algorithms, but I have been having this issue and was rather annoyed at it since it basically could not handle sketches at all properly.
I took a look at the phash.js
file though and read some of the comments, and something in the getHash function caught my eye. It says that it skips over the first value because it can heavily throw off the average... however the iteration doesn't skip anything.
So, I decided to have the x,y start at 1,1 and reduce the average division to match, and suddenly this issue has completely disappeared. I tested all the above images too and they all now produce reasonable outputs.
Am I missing something or was that the issue..? I can make a PR if that's desired, I haven't because I honestly have no idea what the algo is doing and I just made a dumb edit following one of the comments.
Found this issue https://github.com/oliver-moran/jimp/issues/67 which was closed, but...
I still get some images with 0 hash. For example this one.
Getting "1000000000000000000000000000000000000000000000000000000000000000" hash on it.
I was trying to replace pHash.js but without success.