How can I change the default avatar generating method?


I want to provide my own designed avatars as the new user’s defualt avatar, not the one generated by discourse.
Any idea? Thank you

(Jeff Atwood) #2

As of Discourse 1.3, there is a site setting to provide a list of (n) alternative avatars that will be picked at random.

(Jens Maier) #3

Due to the way these default avatars are assigned to users, the avatar is dependent on the username and the length of the default avatars list. This results in two gotchas that might be worth knowing about:

  • When a user’s username is changed, the user might get a new default avatar.
  • When a new avatar is added, everyone’s default avatars are reshuffled; if the new avatar is removed, everyone returns to the previous default avatars.

(Jeff Atwood) #4

Hmm that second case is not really desirable @eviltrout, any way to stabilize that which is not too hard?

(Jens Maier) #5

There is a consistent hashing technique where, applied to this problem, on average 1/(2*n) users would be assigned a new avatar and experience sudden avatar change if a single avatar is added (n being the list’s length before adding a single new avatar) and half the users would get a new avatar if the avatar list is doubled

(Avatars are distributed around the edge of a circle, usernames are hashed into angles, the avatar closest to the angle is chosen. Avatar distribution should be static, so there’s a significant chance that with small avatar lists, some avatar will appear disproportionately often or rarely.)

Still, that’s not ideal and while there are consistent or stable hash distributions, those usually depend on the state provided by a hashtable’s buckets to achieve stable bucket assignments after changing the bucket count.

(Robin Ward) #6

As @elberet points out that is a tricky problem to solve.

We’d have to store the hashed avatar at the time the user was created. That’s the only way I can think of safely doing it.

(Jeff Atwood) #7

How difficult would it be to store that in a user field somewhere? It does bug me that these will shift for every new user, if any are added or removed…

(Robin Ward) #8

It’s not simple unfortunately. If I add a field I have to make sure it’s passed up to the client every place an avatar can be displayed. I could try squeezing it into another unused field like the avatar_template but that might make our code more confusing.

I agree it’s bad though, we might have to suck it up.

(Jens Maier) #9

If you’re going to spend significant time on avatars, can I suggest making avatar providers fully modular and plugin extensible? Ideally, letter avatars, Gravatars, and uploaded avatars themselves would be implementable as pure plugins…

(ljpp) #10

Is it possible to define default avatars so that they have first letters of the first name and family name? So that Jeff Atwood would generate an avatar with “JA” or “J.A.”.

I am thinking of a small organization private comunity case, where real names would be preferred rather than aliases. This kind of avatars would support visual indefication of forum members, in polls and such.

(Sam Saffron) #11

It is technically possible, but someone is going to need to write an avatar service for that. Default avatar url is can be customized from site settings, no changes to core are required.

(Régis Hanol) #12

Also, good luck having 2 letters properly centered in a circle :stuck_out_tongue_winking_eye:

(Mittineague) #13

I don’t think the trick is so much getting them centered as it is getting them to look centered. (this was covered in discussing single letters, two letters magnifies the problem)

For example, these are centered but some don’t look it.

(David Collantes) #14

I think it is an optical illusion. They look pretty centred to me.

(Régis Hanol) #15

Yeah, that’s what I meant by “properly centered”.