https://en.wikipedia.org/wiki/Perceptual_hashing
Hash all the images in a separate table and make it searchable. It's a lot of work but it also makes dealing with DMCA much easier as you can automate removal of obvious infringements and illegal content that's spreading.