You could retrieve and store the MD5 checksum for each image. Check out the Digest::MD5 modules for more on calculating the value. There are caveats to doing it this way - such as getting false positive matches - but it may at least point in a direction you can go.