-5

Need to compare below image urls:

https://cdn-image.foodandwine.com/sites/default/files/original-201404-HD-buckwheat-crepes.jpg https://test-static.onecms.io/wp-content/uploads/sites/9/2014/04/original-201404-HD-buckwheat-crepes.jpg

Please provide solution.

nrs
  • 937
  • 3
  • 17
  • 42
  • What do you mean by that, you want to compare urls or you want to compare the content of image is exactly same or not ? – Sarfraaz Jan 23 '20 at 10:10
  • 6
    Does this answer your question? [How to compare two images using Node.js](https://stackoverflow.com/questions/18510897/how-to-compare-two-images-using-node-js) – Mat Sz Jan 23 '20 at 10:11
  • See also [Compare two Images in JavaScript](https://stackoverflow.com/questions/6066111/compare-two-images-in-javascript) – ggorlen Apr 24 '22 at 02:39

2 Answers2

2

The smallest, simplest and fastest JavaScript pixel-level image comparison library, originally created to compare screenshots in tests.

Features accurate anti-aliased pixels detection and perceptual color difference metrics.

Inspired by Resemble.js and Blink-diff. Unlike these libraries, pixelmatch is around 150 lines of code, has no dependencies, and works on raw typed arrays of image data, so it's blazing fast and can be used in any environment.

By this library, you can easily compare the images.

const numDiffPixels = pixelmatch(img1, img2, diff, 800, 600, {threshold: 0.1});
ggorlen
  • 44,755
  • 7
  • 76
  • 106
Imran Khan
  • 21
  • 2
-5
var url1 = "https://cdn-image.foodandwine.com/sites/default/files/original-201404-HD-buckwheat-crepes.jpg";
var url2 = "https://test-static.onecms.io/wp-content/uploads/sites/9/2014/04/original-201404-HD-buckwheat-crepes.jpg";
if (url1 === url2) {
    //is equal
} else {
    //not equal
}
Green Ball
  • 64
  • 9
  • 1
    That would be comparing `URL` of the image. Not the actual content. – Muhammad Zeeshan Jan 23 '20 at 10:19
  • 1
    For sure. He want's to compare the images not image sources – Muhammad Zeeshan Jan 23 '20 at 10:20
  • oh, so it does matter ;) – Green Ball Jan 23 '20 at 10:21
  • 1
    I want to compare images. – nrs Jan 23 '20 at 10:22
  • sure but you should provide more informations, and previous effort – Green Ball Jan 23 '20 at 10:23
  • it is also why people dislike your post – Green Ball Jan 23 '20 at 10:24
  • To be honest i really don't know anything about js and nodejs...I tried opencv and pixelmatch but am not able to achieve it. If possible please help me – nrs Jan 23 '20 at 10:25
  • You need to `npm install pixelmatch` first to use the library Here is everything you should need: `const pixelmatch = require('pixelmatch');` `const img1 = Buffer.from("https://cdn-image.foodandwine.com/sites/default/files/original-201404-HD-buckwheat-crepes.jpg");` `const img2 = Buffer.from("https://cdn-image.foodandwine.com/sites/default/files/original-201404-HD-buckwheat-crepes.jpg");` `const numDiffPixels = pixelmatch(img1, img2, null, , );` `console.log(numDiffPixels);` and should be replaced by the correct image with and height – Green Ball Jan 24 '20 at 02:52
  • use https://beautifier.io to make the code readable – Green Ball Jan 24 '20 at 02:55