There is no universal solution, there are a few algorithms like SURF [1], SIFT [2], Winsurf [3], dhash (the one presented here), ahash [4], phash [5] each concentrating on a particular feature of the image and has it's strong points and weak points.
Many of the steps are similar to ideas used in the scale-invariant feature transform [1]. See also the original paper [2] and an early use for automatic image stitching [3].
[1] http://en.wikipedia.org/wiki/Scale-invariant_feature_transfo...
[2] http://en.wikipedia.org/wiki/SURF
[3] http://www-db.deis.unibo.it/research/papers/IWOSS99.ABP.pdf
[4] http://www.hackerfactor.com/blog/index.php?/archives/529-Kin...
[5] http://www.hackerfactor.com/blog/index.php?/archives/529-Kin...