Digital Consumption


 Charles Darke | 21 January 2007
I've created Visiglyphs --- a PHP implementation of a 9-block pattern which can generate a pattern from a seed value. Visiglyphs are useful to distinguish different data visually:


I've integrated this into my blog to provide a visual representation of the IP address of comments. The actual data represented is actually an MD5 hash of the IP address (plus salt) to prevent an attacker from working out an IP address from a hash. Using visiglyphs for IP visualisation was an idea I found on Don Park's page.

IP visualisation is useful on web discussion forums to identify trolls posting under multiple IPs. Of course, this is trivially defeated by using proxies.

However, visiglyphs can be used for visually representing any data in a glyph. I'll do a bit more testing and if there's demand, I'll release the source code.

Update: a development copy of the Visiglyphs source code has now been released. Note that this code has been written from scratch without reference to any other implementation. Consider this as a release into the public domain so you can do whatever you like with it. Have fun!

Update: to save you from having to post a comment to see your visiglyph, I've put a preview below:

Update: Alex has modified my code and produced a OOP PHP version here.

Update (18 May 2008): New version now available. Re-written so as not to require imagerotate() function (anyone using Debian will understand) and also clean up some code.

One important thing to note is that the algorithm has changed slightly, the sub-blocks were previously rotated before use and so this new version will generate glyphs that look slightly different. Upgraders will need to either clear out the old cache OR re-write the code to simulate the extra rotation. 


Comments (48)

Please note that you'll see that the comments on older comments on my site have the same glyph. This is because I didn't store IP addresses on posts until part way through the development of my blog!

These posts and my posts (I don't store IP address for my own posts when logged in) will therefore have the same glyph.
  Written by Charles Darke at 4:57pm, 21 January 2007.
A few notes on my implementation:

- I did it from scratch without reference to Don's code and so the principle is the same, but the implementation is different.

- I used my own set of blocks. In particular, I replaced those that were invariant under 90 degree rotation with those that are not. This is because I use 2 bits of entropy to determine the rotation of a block.

- Glyphs sizes are in multiples of 3 and sizes above 24 are drawn directly but those smaller are drawn at 24 and then re-sampled down to the smaller size to give a better appearance.

- A glyph can store about 180 bits of entropy. This can be increased by increasing the number of basic block designs. The human distinguishable glyphs are probably much smaller since colours are encoded into 24bits .
  Written by Charles Darke at 5:04pm, 21 January 2007.
Hey, I'm interested in your Visiglyph implementation. Any chance to release your code under an open license?
  Written by Guest: And at 5:19pm, 21 January 2007.
Yes, I'll be releasing under an open source licence once I've finished the glyph cache and done a bit more testing.
  Written by Charles Darke at 5:29pm, 21 January 2007.
Looks great, Charles. :-)

I tried the two color version some time ago in an unreleased project but, because the result looked like flowers at small size and random-ish perception-wise at large size, I went with one color approach this which promotes geometric shape more.

Visiglyph? Hmm. Not a bad name.
  Written by Guest: Don Park at 5:37pm, 21 January 2007.
I could convert Don's code to PHP, but if you've already done the work, it would make my life easier if you'd release the source code.
  Written by Guest: Scott Reynen at 5:41pm, 21 January 2007.
@Scott: I'm going to package it up later tonight and release it once I've ironed out a few bugs.
  Written by Charles Darke at 5:48pm, 21 January 2007.
OK. The cache should be done now. My setup uses .htaccess to re-write the .png request to to the PHP script. This will trick some browsers to cache the visiglyph as a .png file anyway.

If the request is the first time the glyph is requested, the glyph is generated on-the-fly and the output is written to the cache.

Subsequent requests to the glyph will be directed to the disk cache by the .htaccess rules.

The file request contains a nonce to prevent disk exhaustion attacks.
  Written by Charles Darke at 6:54pm, 21 January 2007.
If people are interested, I can release an early version for you to play with before the release of the more polished version.
  Written by Charles Darke at 7:05pm, 21 January 2007.
@Don

Thanks for coming up with the original idea! My implementation has slightly less geometric impact than yours for two reasons: one is using two colours (but this is configurable). The second is that I use slightly more complex/detailed blocks.

I'll probably revise the code to draw simpler blocks.

>Visiglyph? Hmm. Not a bad name.

I like it, it's the name that's in my head when I work on it
  Written by Charles Darke at 7:12pm, 21 January 2007.
Really cool implementation for avatars here.
  Written by Charles Darke at 11:03pm, 21 January 2007.
A development copy of the Visiglyphs source code is now available here. Have fun!
  Written by Charles Darke at 11:22pm, 21 January 2007.
What if we hate our "visiglyph"? May we petition for a modified algorithm??
  Written by Guest: Anonymous at 7:20pm, 23 January 2007.
What if we hate our "visiglyph"? May we petition for a modified algorithm??

Actually, yes! You can change the salt value to vary the glyphs according to taste.

You can also hash together a user supplied cookie. This means that each user will see their own version of the visiglyph which would also mean more disk space required for cache. This feature isn't implemented in my code but is easy to do.

Would be useful for 'offensive' visiglyphs. I noticed that Don's experienced some swastika like glyphs.
  Written by Charles Darke at 7:29pm, 23 January 2007.
Awesome! I was waiting for someone to implement the identicon thing in PHP.

How about some usage example? I mean I know the source code is right there, and it's not perfected yet but if you could give us a pointer or two on how to use this code.

Anyways, good job! Thanks!
  Written by Guest: Luke at 4:35am, 24 January 2007.
Cool !
A while back, I wrote a similar PHP script to make an avatar out of an IP. I've never used the script, tho
I've uploaded the result here : http://planetozh.com/projects/ip2avatar/ip2avatar.php
It's using a fully configurable .ini file to make various shapes (browse in directory to see the example file)
  Written by Guest: Ozh at 7:04am, 24 January 2007.
@Luke

Hopefully the PHP code is self-explanatory. If I have time, I'll post a more detailed 'how-to' guide, but hopefully somebody will beat me to it
  Written by Charles Darke at 1:07pm, 24 January 2007.
Cant seem to extract the source code file, it says it's damaged. Using Winrar on Vista.
  Written by Guest: Anonymous at 4:44pm, 24 January 2007.
Cant seem to extract the source code file, it says it's damaged. Using Winrar on Vista.

Try opening it in a text editor. It's a single file for convenience. It may already be un-gzipped depending on your browser (and my server configuration).
  Written by Charles Darke at 5:10pm, 24 January 2007.
Thanks, renaming it worked fine.
  Written by Guest: Anonymous at 7:52pm, 24 January 2007.
I've been playing with your code and it runs fine with the ip set to random, but whenever I try to get a real ip the visiglyph comes out with the right shape but completely black. I must be doing something wrong...
  Written by Guest: Eric at 8:25pm, 24 January 2007.
@Eric

I think you may be feeding an IP into it directly. I can post example usage code later, but you should really feed it a hashed IP.

e.g. replace

$ip=md5(rand(0,300));

with

$ip=md5($_SERVER['REMOTE_ADDR'].VISIGLYPH);
  Written by Charles Darke at 8:47pm, 24 January 2007.
Great idea for creating blog entries but if you get many responses from the same IP area or from the same IPS will the icons look similar?
  Written by Guest: Darryl at 9:53pm, 24 January 2007.
Great idea for creating blog entries but if you get many responses from the same IP area or from the same IPS will the icons look similar?

If you have the same IP, the glyph will be identical. If you have a different IP, the glyph will look different. There is no correlation between the appearance of a glyph and the IP since the IP is passed through a cryptographic hash function which scrambles it beyond recognition.
  Written by Charles Darke at 9:56pm, 24 January 2007.
Thanks Charles. I noticed the md5 right after I posted earlier, so I got it working. I'm working on adding it to a PHP game that I'm making. I would post the link to the game, but at this point the visiglyphs are just about the only thing working as they should.
  Written by Guest: Eric at 11:22pm, 24 January 2007.
Cool feature. I had some problems getting started, because my PHP version didn't recognize the imagerotate function (I had installed gdlib later, and not 'with' my PHP, and then this function is not available).
I don't know much about configure/compile PHP, but after looking a little further, I found and rewrote a function from the comments on PHP.net, which replaces this function.

The only 'problem' I still have is the appearance of a black line sometimes in the graphic, and always on the edge of the graphic (left side).

Thanks for releasing the code!
  Written by Guest: phalab at 12:21pm, 1 February 2007.
There are still some 'artefacts' in my code. You'll see the 4th glyph example in the post shows a spurious line in my code I was hoping someone would be able to track down the cause of these.
  Written by Charles Darke at 12:57pm, 1 February 2007.
Hi,

I tried to get rid of those artifacts, since I had that black line on the left myself. I felt the imagerotate caused this, and therefore I figured instead of rotating and pasting the image back in, I would rotate the 'points-array' itself, and draw the image again.
It seems to work. My provider has PHP 4 without gdlib, so I can't really show it, but I can show you the code:

http://barst.com/glyph/

Regards,
Alex
  Written by Guest: phalab at 7:08am, 3 February 2007.
This is the coolest thing since the last thing that was the coolest thing ever. I look forward to seeing an 'official' public release of this because I am totally gonna make a plugin for b2evolution. Between now and then I'm going to tinker with seeds until MY ip makes a cool visiglyph.
  Written by Guest: EdB at 8:38am, 3 February 2007.
I tried to get rid of those artifacts, since I had that black line on the left myself. I felt the imagerotate caused this, and therefore I figured instead of rotating and pasting the image back in, I would rotate the 'points-array' itself, and draw the image again.
It seems to work. My provider has PHP 4 without gdlib, so I can't really show it, but I can show you the code:

http://barst.com/glyph/

Good job! I'm glad somebody made the code workable! I actually grew up as an assembly programmer so using anything more complicated than a conditional jump is highly alien for me!

Would you mind if I host a copy of the code here? Your improved code would be much better for others to work from.
  Written by Charles Darke at 9:30am, 3 February 2007.
>(I made an account on your site too now, hehe)

Hmm. Looks like I must have fixed the email/registration problem.

Looks like I gave IP anonymity to registered users too

[Charles: Oops! I tried to reply to your post but looks like I over-wrote your post with my reply. my bad.]
  Written by phalab at 9:37am, 3 February 2007.
I've managed to make an workable rev-0 hack for b2evolution blogs utilizing your code and the version supplied by Alex, and would like to give it away. What I'm doing is not showing the visiglyph until a comment is submitted, then checking to see if I have one for that IP before generating a new one. Either way, the visiglyph is added to the comment prior to adding it to the application's database.

I'd like to know if it's okay to release what I've done to the world wild web. I understand you're working on cleaning up your code, but what I have works. The only way it'll get better is by releasing my implementation to that application's community so they can tinker on it. Your domain and the URL of this post are (naturally) credited internally.

Anyway I won't let it out unless you tell me I can. I'll pop back in from time to time and see if there's any news, or go.hangglide -at- gmail.com works for me.
  Written by Guest: EdB at 5:35am, 10 February 2007.
I'd like to know if it's okay to release what I've done to the world wild web. I understand you're working on cleaning up your code, but what I have works.

I'm glad to see others are finding my (rough) code useful. You can consider my Visiglyph code as public domain and so are free to do whatever you like with it! Unfortunately, I can't speak for Alex so it might be good to confirm with him.
  Written by Charles Darke at 10:22am, 10 February 2007.
Thanks! I hope Alex stops by here and sees this because I can't get anywhere on his web
  Written by Guest: EdB at 12:21pm, 10 February 2007.
Thanks! I hope Alex stops by here and sees this because I can't get anywhere on his web

I think I have his email and will contact him.
  Written by Charles Darke at 1:41pm, 10 February 2007.
Thanks! I hope Alex stops by here and sees this because I can't get anywhere on his web

I got a response back from Alex. The code has been released under a BSD licence. See below:
Hi Charles,

Great to see so many people enjoy it. I've added the BSD license to it. If you need to have a more flexible license, then please let me know.

Kind regards,
Alex
  Written by Charles Darke at 10:54am, 10 April 2007.
Hey thanks! I was just updating my little hack and came back to see if there was anything new.

Have fun!
  Written by Guest: EdB at 12:37pm, 29 November 2007.
Hey thanks! I was just updating my little hack and came back to see if there was anything new.

No probs. I did see your hack being used in a few places. Good to see this stuff being useful
  Written by Charles Darke at 2:34pm, 29 November 2007.
Update (18 May 2008): New version available (see body of post above).
  Written by Charles Darke at 12:48am, 18 May 2008.
Updated the examples above to show the experimental version I'm currently running which uses graduated colours.
  Written by Charles Darke at 11:13pm, 23 May 2008.
pretty cool, I think all sites should use these.
  Written by Guest: skvmb at 4:40am, 13 January 2009.
Great work! Thx for releasing as open source. Unfortunately it did not work out-of-the-box. An error "header already send" occured. Fixing is easy: Remove all blanks at the beginning and end of the script "glyph.php", that means all blanks before opening php tag <?php and ending php tag ?>. Hope this helps.
  Written by Guest: Robert Westenkirchner at 6:25pm, 2 February 2009.
The linked file does not exist at the moment.
  Written by Guest: Janis at 7:38pm, 23 March 2009.
The linked file does not exist at the moment.

Thanks for the heads up! Not sure what killed the file. I'll see if I can find it in a backup.
  Written by Charles Darke at 7:46pm, 23 March 2009.
The linked file does not exist at the moment.

Hi. Unfortunately, I'm out of the country and the file is not available in local backup, so I will need to get from offsite backup.

However, it appears that the latest version is not available, but the previous version to that is still available.

This will teach me to use my CMS properly instead of putting adhoc files in and then deleting them!
  Written by Charles Darke at 7:52pm, 23 March 2009.
The linked file does not exist at the moment.

Managed to pull file from another computer (hurray for ssh and backups everywhere) so link should now work.
  Written by Charles Darke at 8:28pm, 23 March 2009.
First version of Visiglyph code is released under public domain, right? Can I use my own optimized implementation of these Visiglyphs in closed-source projects?
  Written by 12345630430 at 10:35pm, 24 February 2012.
First version of Visiglyph code is released under public domain, right? Can I use my own optimized implementation of these Visiglyphs in closed-source projects?

Yes, the first version was PD so you can do whatever you want with it. Of course, any contributions of code back would be appreciated.
  Written by Charles Darke at 1:07pm, 9 March 2012.