Subscribe to RSS feed

splitbrain.org - electronic brain surgery since 2001

MonsterID as Gravatar Fallback

Today I stumbled across a link at Simon Willison's blog:

Visual Security: 9-block IP Identification
Smart (and pretty) trick for showing a representation tied to a commenter’s IP address without affecting their privacy

IdentIcon It is very cool indeed. Don Park's idea is to use a commenter's IP address to generate a pretty graphic from a few basic shapes. By combining multiple types of shapes, different colors and rotation it is possible create a lot of different graphics. They then can be used as a kind of avatar to make comments by the same poster easy to spot. He calls this “identicon”, you can see the one generated for my IP on the right.

Here at my blog I currently use the Gravatar service to display avatars in the comments. Unfortunately this means users need to sign up at the Gravatar site1). Only a few commenters already did that, for all others a boring “no avatar” image is displayed.

Fortunately Gravatar lets you send them a redirect URL with the query for the avatar image which will be used if the commenter doesn't have a Gravatar. The next logic step is to use this to redirect back to a similar mechanism as Don Park's identicon. But aren't geometrical graphics a little bit boring? I thought so and Don Park did as well and listed a few other image generator examples that could be used as well. One of them being Combinatoric Critters. Check it out, its an automatic generator for cute little creatures.

I loved the idea and fired up my GIMP to create my own little monsters…

A random monster

The above is a randomly generated one. Interested in how the code behind it works? Read on…


It's simple: A monster is created from the following parts: body, arms, legs, eyes, mouth and hair. For each of the parts I created multiple versions – each in it's own PNG image. All I need to do then is using PHP's image support (libGD 2) to merge the images. Lets have a look at the code:

<?php
build_monster($_REQUEST['seed'],$_REQUEST['size']);
 
function build_monster($seed='',$size=''){
    // init random seed
    if($seed) srand( hexdec(substr(md5($seed),0,6)) );
 
    // throw the dice for body parts
    $parts = array(
        'legs' => rand(1,5),
        'hair' => rand(1,5),
        'arms' => rand(1,5),
        'body' => rand(1,10),
        'eyes' => rand(1,10),
        'mouth'=> rand(1,10)
    );
 
    // restore random seed
    if($seed) srand();
 
    // create backgound
    $monster = @imagecreatetruecolor(120, 120)
        or die("GD image create failed");
    $white   = imagecolorallocate($monster, 255, 255, 255);
    imagefill($monster,0,0,$white);
 
    // add parts
    foreach($parts as $part => $num){
        $file = dirname(__FILE__).'/parts/'.$part.'_'.$num.'.png';
 
        $im = @imagecreatefrompng($file);
        if(!$im) die('Failed to load '.$file);
        imageSaveAlpha($im, true);
        imagecopy($monster,$im,0,0,0,0,120,120);
        imagedestroy($im);
    }
 
    // resize if needed, then output
    if($size && $size < 400){
        $out = @imagecreatetruecolor($size,$size)
            or die("GD image create failed");
        imagecopyresampled($out,$monster,0,0,0,0,$size,$size,120,120);
        header ("Content-type: image/png");
        imagepng($out);
        imagedestroy($out);
        imagedestroy($monster);
    }else{
        header ("Content-type: image/png");
        imagepng($monster);
        imagedestroy($monster);
    }
}

You see it's not much code for the real work. To use MonsterID as an identification (eg. the same commenter always gets the same monster assigned) I used a simple trick: I choose body parts with the rand function but initialize the random generator with a value dependent on a provided identification. For this I use the same email MD5 sum that is used to get the user's Gravatar.

Do you like it? Cheer up! I hereby release the code and graphics under the Creative Commons Attribution 2.5 License – unleash the monsters…

Update: Because many people seem to like it, I just enhanced the package a little bit and gave it its own project page. I added a few more bodies and eyes and assign the body color dynamically as well. This makes the monsters even more distinguishable. Get your monsters at MonsterID.

Tags:
monsterid,
gravatar,
avatar,
php
Similar posts:
1) which is not possible currently, because the signup is closed until February
Posted on Saturday, January the 20th 2007 (3 years ago).

Comments?

1
Great job, Andi. Aside from critters, I like the random skeleton shadow generator which would be pretty cool for gamer communities.
2007-01-21 00:03:29
2
Very nice. I saw the combinatorial critters and thought exactly the same thing. However, I'm not a very good artist so I implemented the 9 block method :)

The 9 block is also better in more compact spaces, but for identity purposes, MonsterID clearly has more personality :)
2007-01-21 00:08:34
Charles Darke
3
Testing... this is really cool.
2007-01-21 00:19:11
4
This is so playful.  I have a couple sites that could use something like this.
2007-01-21 00:44:25
Paul Burney
5
Neat, but does this actually maintain the same image between subsequent comments? Using the email to determine the seed rather than the value for each body part, I don't know how it could.
2007-01-21 01:28:52
Scott Reynen
6
You gotta do what Don does and render the glyph in the comment form so we don't have to post to find out what ours is. :)
2007-01-21 01:54:58
Jeff Atwood
7
Jeff, I can't display the monster before you comment, because I use the e-mail address you enter to seed the generator.

Scott, Seeding the generator with a fixed value (created from your e-mail) will cause subsequent calls to rand() to produce the same sequence of "random" numbers.
2007-01-21 11:17:28
8
Awesome work, those little guys rock :) Will see to somehow integrate them into my s9y as well, they are just too great :D
2007-01-21 11:18:50
9
Andi, about Jeffs request, you could display the monster via javascript as soon as the email-input-field's value changes. I hacked together a quick demo, dunno how the impact of this would be if many people use it simultanously, and the JS could prolly be better as well (haven't used JS for a looong time): http://foosel.net/monsterid/demo.html
2007-01-21 11:45:03
10
Nice work foosel, but I don't use the clear address as seed but transmit it MD5 encoded instead (to avoid making it available unobfuscated to harvesters), so I'd need to add a JavaScript MD5 implementation... I think a little surprise is okay ;-)
2007-01-21 11:59:54
11
Ok, that's a reason of course ;) Wouldn't be worth adding some K's of libraryfunctions (prolly exaggerated value, but anyways...) just for a simple preview, I agree :)
2007-01-21 12:02:41
12
You could always have a clear-email fallback just to talk to the preview javascript (which would never appear to harvesters obviously). Anyhow great idea and cute monsters :)
2007-01-21 13:10:08
Sunny
13
Priceless. Almost makes me want to delete my Gravatar. (I'm definitely installing this once I have some time.)
2007-01-21 17:48:39
pjm
14
Great idea. I made a quick Wordpress plugin based off your code (http://scott.sherrillmix.com/b … monsterid/). Hope that's ok?
2007-01-21 18:34:51
15
Andi, since your version uses hand-drawn parts, why not take the next step and let people contribute new parts? This will turn it into an evolving visual language of sort. Faces can talk after all. ;-)
2007-01-22 07:45:12
16
I really like the idea, it's the beginnig of 'monsterization'. Every site will have its own custom monster avatar. The problem will be with people with dynamic IP...am I right?
2007-01-22 12:56:57
Fernando
17
Don: yes, adding new "Monster Packs" should be simple. Adding new parts to the existing ones needs careful work or parts won't match together. Also changing the number of available parts changes all already assigned monsters, but I guess that isn't too bad.

Everybody: feel free to send me new images.

Fernando: no, dynamic IPs don't matter because the email address is used, not the IP address like in Don's identicon implementation.
2007-01-22 13:07:39
18
I kinda like this better than the original. And no chance of a swastika being made. Cool work!
2007-01-22 16:06:00
Frank
19
Food for Thought: I think the monster 'body' may be 'too strong' visually when compared to rest of the body parts which reduces ability to distinguish them. For example, my MonsterID and sean's look very similar because limbs and antennas are only hair thin.

In the end, a well designed MonsterID Pack could require as much expertise and sweat as a good looking font does.
2007-01-22 20:05:34
20
These are great. The only problem with using email addresses is that while these work fine for providing a visual indicator in a discussion -- who's saying what -- they don't help with proving identity, as Don's patterns do (being based on IP address). I can enter Person X's email address and appear to be them.

I know that's not the problem you're trying to solve, but that triggers an interesting idea -- one way around this would be to let users pick their own salt for the hash function.
Email: [blah@expample.com____]
Avatar salt: [ILoveChocolate____]
then the combination of Email + Salt would be used to generate the avatar, which means that unless someone guesses my (low-security) salt, they can't easily impersonate me.

Anyway, great work.
2007-01-23 05:17:08
Paul
21
Shit, this is the first time I regret having set a gravatar :)
2007-01-23 12:36:48
Sam
22
Another alternative for fallbacks is the favatar. http://dev.wp-plugins.org/wiki/favatars
2007-01-23 17:34:40
David
23
Interesting, installed on my blog (without gravatars), but with my own monster parts (designed in inkscape in twenty minutes), take a look at it: http://blogs.kd2.org/bohwaz/
2007-01-25 05:02:53
24
Cool Idea. I wrote a small summary in german about it. You can read this here:
http://www.im-web-gefunden.de/ … bleme-hat/
Greetings from Berlin to B. :)
Thomas
2007-01-25 09:43:34
Thomas
25
As you've mentioned on your main monsterID page - I implemented a similar system.

What's been plaguing me recently is implementing some sort of server cache so a generated image can sit in a directory for a while, so I can dynamically create a "recent readers" with images dynamically generated...

Any ideas how to save a .php dynamically generated image to a server?
2007-03-13 17:43:17
26
Chris, the imagepng function accepts a second optional parameter to save the image to a file.
2007-03-13 19:34:15
27
Ahh so I was barking up the right tree... I guess I should have thought that.

I'll have a play and see if I can set up my paths right. Haha.
2007-03-14 12:13:02
28
So the second path overrights the ability to display the image? Well, it seems to..

http://www.screwyouhippy.com/m … inime2.php now displays a line of text (which is so helpful, but completely not what I want) but *does* upload the image to http://www.screwyouhippy.com/m … s/test.png

I'm assuming I want both my cake and eat it... :(
2007-03-14 12:21:45
29
okay, it seems I haven't had my morning coffee...

Thanks Andy you are a star *bow bow*

(Happily goes away to make a "recent visitors" thingy)
2007-03-14 12:25:12
30
Idea is more nice than performance
2007-04-15 18:35:11
31
This page had a *lot* of comments from people who where just testing. To keep page loads reasonable I deleted all comments which did not add anything to the discussion. Feel free to continue testing, I will continue to delete test comments after some time.

@Peter: the performance of the image generation script isn't too bad. Creating a monster is done in a snap and could be improved by caching the results. If you have to wait a while here, it is because the Gravatars are checked first. Only when a redirect from the Gravatar server comes, the monster will be build. So performance problems are most likely Gravatar server slowness problems.
2007-08-25 21:09:03
32
I quite enjoy the idea of neat looking, personally identifiable graphic for quick verification of identity.  Problem is, I post from a large number of locations, but for the average user, it'd be great.  I may try to implement that in my blogging system.
2007-10-16 07:23:28
33
Very Cool Stuff! I've made a widget initially to display Gravatar avatars, but I recently added support for both MonsterIDs and Identicons. It's hosted with WidgetBox at http://www.widgetbox.com/widget/avatar. You can see it in action at http://zwah.com and http://standoutwidgets.com
2007-12-07 19:01:13
34
this is such a great piece of code. I love the concept.
2007-12-31 23:50:57
35
Can you please give me code in c#
2008-03-07 08:59:46
36
For use alpha channel (transparent background) need replace:
$white   = imagecolorallocate($monster, 255, 255, 255);

to:
$white   = imagecolorallocatealpha($monster, 0, 0, 0, 127); // now color black, but transparent :)

and replace:
imagecopyresampled($out,$monster,0,0,0,0,$size,$size,120,120);

to:
imagealphablending($out, false);
imagesavealpha($out, true);
imagecopyresampled($out,$monster,0,0,0,0,$size,$size,120,120);
2008-05-29 18:39:31
lexazloy
37
Really like the idea. I have posted it on my blog in the list of top new web ideas.
2008-08-13 13:26:13
38
Hi Andreas,

I've just altered your code again on my site (www.screwyouhippy.com) to output a 57x57 "apple-touch-icon.png" to the root of my website.

Now if anyone bookmarks the site with their iPhone they get a random little dude on their home page! :)

Still think your PHP rocks...
2008-12-05 16:13:32
39
I've been using the identicon for a while, or something like it, anyway.  This is an interesting take on the same core concept!
2009-09-08 18:14:23
40
I like the idea to reveal an IP address through its image equivalent. After all, pixel combinations and IP are not like photos, this is not private life.

The digest of the IP or email address used to generate the image is unique. That's interesting, the image is unique and will be searchable using image search engines and image comparators, so I'll be able to search the whole production of someone using a single image available on the company intranet, or a public blog (after the avatar identification technology has spread, indeed). Thanks for that. I'm impressed how tech guys can make the world better.
2009-12-21 13:38:52
bing brother
41
I am about all things cute and adorable!  These little guys are just that!! I have a WP blog and using them is one of my options for my comments.  I fell in love with them at first sight and choose them immediately. Hands Down, no questions asked.

When I’m in the admin section of WP, I see each cute, adorable little monster.  When you look at my blog comments from the “outside” – the horribly boring G for gravatars is there.  Oh the HORROR!!!

Any ideas O great mastermind of monsters??? I do so want them to be displayed on my comments?? So much so, that I found this and now am literally begging for help.  <hands clasped> pretty please?? With reese cups on top??? Peanutbutter in the middle?

Thank you for the cute creatures…..

Marie
@spreadingJOY
2010-01-16 13:47:54
CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.