mozilla / fxa-content-server

DEPRECATED - Migrated to https://github.com/mozilla/fxa
Mozilla Public License 2.0
163 stars 120 forks source link

Every FXA account should get a semi-unique hex color value #1599

Closed johngruen closed 9 years ago

johngruen commented 9 years ago

We should assign every user a color and use that color to modify the fill f the default avatar SVG. This will let us pass semi-unique default profile images into requesting services.

nchapman commented 9 years ago

Food for thought: http://devmag.org.za/2012/07/29/how-to-choose-colours-procedurally-algorithms/

zaach commented 9 years ago

cc @seanmonstar. The choice of color would have to be persisted via the profile-server.

pdehaan commented 9 years ago

Either random, or based off of the email address. I found http://stackoverflow.com/questions/17845584/converting-a-random-string-into-a-hex-colour which was mildly interesting.

function emailToColor(email) {
  var tmp = parseInt(parseInt(email, 36).toExponential().slice(2, -5), 10);
  var stringHexNumber = (tmp & 0xFFFFFF).toString(16);
  return '#' + ('000000' + stringHexNumber).substr(-6);
}

Should give you a consistent color value based on a supplied string/email address. Not sure how you'd verify that there was then enough contrast betweenst the random SVG fill color and the avatar person, unless we found some other color library that returned some complimentary color so it wouldn't ever be white-on-white (or something similar).

vladikoff commented 9 years ago

@johngruen let us know what we will be using this for! We can use the code that @pdehaan posted and get the colour based on the email.