0

The initial task is to process image, hash it, make some heavy image work and store this hash and work results in database, during next request with same image I want to compare the image hashes with hashes I have in database and load database-cached results to reduce amount of heavy work.

So the questions are, what to hash? with what to hash? I see good php implementations of phash but seems to be it is great for similarity check, but we need exact matching. Is phash fine for exact mathing also?

Thank you!

Cassius
  • 153
  • 13
  • Welcome to Stack Overflow. [Read here](http://stackoverflow.com/help/mcve) for more information about how to create a Minimal, Complete and Verifiable question. – Toby Jul 30 '16 at 00:30

1 Answers1

1

PHP provides a built-in function for this, which is probably the easiest solution:

$hash = hash_file("sha1", '/path/to/image');

You can use this check for exact matches. There is a small chance of collisions, but you can help mitigate that by also using the file path or database ID in your comparison.

The answers in this similar question provide more options.

Community
  • 1
  • 1
mister martin
  • 5,746
  • 3
  • 24
  • 58