6

Users of stackoverflow.com who do not upload their photos have an image pattern in their photo area. These are simple but different for all users and that is very impressive. Each one has a central square and outer border, both are usually filled with patterns. Is the code for making these image patterns available or how can they be created? Can they be created in R?

Mark Miller
  • 12,483
  • 23
  • 78
  • 132
rnso
  • 23,686
  • 25
  • 112
  • 234
  • Perhaps related: http://stackoverflow.com/questions/415/decode-email-address-from-gravatar-hash – Matthew Lundberg Jun 22 '14 at 02:31
  • 1
    There's some info and php source [here](http://scott.sherrillmix.com/blog/blogger/wp_identicon/) – jbaums Jun 22 '14 at 04:55
  • 1
    I do not know the code used, but if there is a library of small symbols in `R`, perhaps associated with `plot`, you could probably create an identicon using 16 of those symbols and one or two rules to govern symmetry. I have not tried it. This would make a good `Code Golf` puzzle. – Mark Miller Jun 22 '14 at 17:35
  • 1
    I had a bit of a play with this [gist here](https://gist.github.com/johnbaums/c0b90ab1d6a29599359a) - the randomisation is greatly simplified (in part because of R's restrictions on seed size), so it won't generate identicons identical to the Gravatar service. – jbaums Jun 23 '14 at 18:14

1 Answers1

7

Compute a hash of the email address with package digest:

d <- digest('ab@c.com', algo='md5', serialize=FALSE)
d
## [1] "b1554c62bf1d05a4a9c48754a6619c17"

Then ask gravatar for the image:

download.file(paste0('http://www.gravatar.com/avatar/', d, '.png?d=identicon'), mode='wb', destfile='ab.png')
## trying URL 'http://www.gravatar.com/avatar/b1554c62bf1d05a4a9c48754a6619c17.png?d=identicon'
## Content type 'image/png' length 2280 bytes
## opened URL
## ==================================================
## downloaded 2280 bytes

enter image description here

The mode='wb' is required for Windows systems. mode='w' is the default, and the b flag is ignored on non-Windows systems.

Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112