Looking through the documentation of these two node packages:
https://github.com/aheckmann/gm
https://github.com/rsms/node-imagemagick
trying to figure out if it is possible to generate a perceptual hash of an image using it.
I'm already using these packages in my project so would be nice to find the hash functionality instead of adding extra package like Jimp.
Any kind of help is highly appreciated!
EDIT 1:
So after looking at all the links and suggestions from you guys I've tried following
gm()
.command("convert")
.in("testImage.jpeg")
.in("-verbose")
.in("-moments")
.write( "testOutput.json", function (err) {
if (!err) {
console.log("DONE :)");
}
else {
console.log("ERROR :(");
console.log(err);
}
});
It gives me this huge output, but the part I'm interested in is here:
"channelPerceptualHash": {
"colorspaces": [ "sRGB", "HCLp"],
"Channel0": {
"PH1": [0.514487, 11],
"PH2": [3.46339, 11],
"PH3": [4.96178, 11],
"PH4": [5.09255, 11],
"PH5": [10.2783, 11],
"PH6": [7.0728, 11],
"PH7": [10.2625, 11]
},
"Channel1": {
"PH1": [0.514487, 11],
"PH2": [3.46339, 11],
"PH3": [4.96178, 11],
"PH4": [5.09255, 11],
"PH5": [10.2783, 11],
"PH6": [7.0728, 11],
"PH7": [10.2625, 11]
},
"Channel2": {
"PH1": [0.514487, 0.514487],
"PH2": [3.46339, 3.46339],
"PH3": [4.96178, 4.96178],
"PH4": [5.09255, 5.09255],
"PH5": [10.2783, 10.2783],
"PH6": [7.0728, 7.0728],
"PH7": [10.2625, 10.2625]
}
},
"renderingIntent": "Perceptual"
According to this thread http://www.imagemagick.org/discourse-server/viewtopic.php?t=30258
if I'm not mistaken, I can do the comparison of these PH values to determine if the image is the same or not.
EugeneGordin
. Your link is not working for me. The server is having problems. But see fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/…. Usecompare -metric phash image1 image2 diffimage
or if you just want the compare values and not the difference image, then usecompare -metric phash image1 image2 null:
. But I am surprise that gm convert is using ImageMagick and not GraphicsMagick, which does not have this perceptual hash. But I have never used gm convert, only convert from ImageMagick. – fmw42