I'm convinced the tags are just random, seeded by message ID. The images themselves don't seem to be checked at all.
Ahh, I never tried using an image that had already been posted - does it give different results? Would have been a nice little Easter egg though.
The image doesn't matter. Even a broken URL will give you a badge. It takes your first post in the thread that has an img tag and I think Foxpup is right about it using the message ID to derive a random number. So changing the image in an existing post won't do anything. Removing the post (or removing img tags from it) and posting a new one will give you a new badge.