elixir-image/image

Compare image for duplicate

Closed this issue · 2 comments

Let’s say I have an image already uploaded and stored in the system.

When a user upload the same image for instance, is there a way to compare with existing list of images by the same user and see if it is duplicate indeed. If not then allow the user to upload otherwise throw an error.

Is there comparison of images for duplicate feature is available? If not this feature is awesome to have.

tielur commented

@ridzria you might be better off doing something like a md5 checksum comparison or something along those lines

@ridzria, the function Image.dhash/1 may be what you're after. It generates a variation of a perceptual hash and does a reasonable job of checking if images are "the same" irrespective of size or format. You'll see the references to the original implementations in the docs.

Please note that the original generates 64-bit hashes. My function generates 512-bit hashes. Which means I've done something different in my implementation but I haven't taken the time to dive deeper into it.

Please do let me know if Image.dhash/1 does what you need?

Usage

def kinda_same?(image_1, image_2) do
  Image.dhash(image_1) == Image.dhash(image_2)
end