title: Find similar images in (pure) PHP / MySQL
body: <p>My users are uploading images to my website and i would like first to offer them already uploaded images first. My idea is to 
   1. create some kind of image "hash" of every existing image
   2. create a hash of newly uploaded image and compare it with the other in the database</p>
  
  <p>i have found some interesting solutions like <a href="http://www.pureftpd.org/project/libpuzzle" rel="nofollow noreferrer">http://www.pureftpd.org/project/libpuzzle</a> or or <a href="http://phash.org/" rel="nofollow noreferrer">http://phash.org/</a> etc. but they got one or more problems</p>
  
  <ol>
  <li>they need some nonstandard extension to PHP (or are not in PHP at all) - it would be OK for me, but I would like to create it as a plugin to my popular CMS, which is used on many hosting environments without my control.</li>
  <li>they are comparing two images but i need to compare one to many (e.g. thousands) and doing it one by one would be very uneffective / slow ...
  ...</li>
  </ol>
  
  <p>I would be OK to find only VERY similar images (so e.g. different size, resaved jpg or different jpg compression factor).</p>
  
  <p>The only idea I got is to resize the image to e.g. 5px*5px* 256 colors, create a string representation of it and then find the same. But I guess that it may have create tiny differences in colors even with just two same images with different size, so finding just the 100 % same would be useless.</p>
  
  <p>So I would need some good format of that string representation of image which than could be used with some SQL function to find similar, or some other nice way. E.g. phash create perceptional hashes, so when two numbers are close, the images should be close as well, so i just need to find closest distances. But it is again external library.</p>
  
  <p>Is there any easy way?</p>