Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating user image pattern, identicon, of stackoverflow.com

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?

like image 489
rnso Avatar asked Jun 22 '14 02:06

rnso


1 Answers

Compute a hash of the email address with package digest:

d <- digest('[email protected]', 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.

like image 110
Matthew Lundberg Avatar answered Oct 02 '22 02:10

Matthew Lundberg