Spot the duplicates, using a Gravatar identicon hack

A project at work needed me to write a UI to find and delete duplicate attachments on a single post, from a client’s WordPress website. Creating a couple of queries where I could look over each post in turn, and check a hash for each file attached, then spot the duplicate hashes wasn’t too hard. Where I was struggling was making the rows with the duplicates stand out visually, file hashes, e.g. bc38d8d8993b5e9f4617576d2adeb875, are just not that easy to distinguish from other hashes, e.g. dbe0256fe35b88ebd4e4e433604b7487… see the problem?

What I wanted was some way of mapping a file hash to a colour, or something strongly visual. Which is when it occurred to me; Gravatar could do this!

So I pretended all my filehashes were the local portion of email addresses, e.g. dbe0256fe35b88ebd4e4e433604b7487@example.com, and Gravatar auto-generates lovely identicon images for each, and there’s my visual differentiation. Here’s what I ended up with:

Gravatar identicons for file hashes

The Gravatar identicon API is really nice and easy to use; you just add an HTML IMG tag to the page and craft a special URL. Here’s an example:

<img alt="" src="http://www.gravatar.com/avatar/<?php echo md5( "{$hash}@example.com" );" />?d=identicon&s=30" class="file-identicon" />

The d URL parameter specifies identicon, as you can see, and the s parameter specifies a size of 30 pixels square.

Join the Conversation

1 Comment

  1. Very clever! I don’t know that I’ll ever need to use this idea but I have to admire the devious mind that came up with it. :)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.