Can I compare two images in Javascript?

Is there a way to compare two image files with different file names? So I look at how equal they are with javascript. Is it possible?

Usage for this: I have a gallery of images that I need to pop up in the lightbox. When the lightbox opens, I will connect to the callback to check for duplicate images and when they are found, remove them from the lightbox gallery so that users do not see duplicate images.

+5
source share
3 answers

I think you could. Psuedocode:

  • Check if the images have the same width and height. If not, they cannot be the same.
  • Create a canvas that matches both images side by side.
  • .
  • --. , , getPixel HTML Canvas?
  • , .
  • O (wh), , .
+5

, .

.

0

, .

, javascript, , URL- , SO: JavaScript

Basically, you convert an image into an element canvasand use the value base64to compare the two, just as people confirm that the document is "valid" by checking the checksum of this document.

0
source

All Articles