That's a good idea. It's a little complicated but it works well. And even if you're not using it to see if two images are the same, it is a good way to be fairly sure that two filenames won't overlap-- the odds are severely against coincidental overlap-- less than 1/1,000,000.

I've used the same idea for creating thumbnails: the user uploads an image and that is stored somewhere, and a thumbnail sized image is also generated and saved as a hashed version of that image-- so if there are two images with the same contents, the thumbnail is reused.