Generate Letter Icon from Name instead of Username?


(Jay Pfaffman) #1

I’m doing an import and all of the usernames are integers. Most users have avatars, but those that don’t end up with something like as their avatar.

Is there some way to have them generated by their name rather than username?

Perhaps the importer can call LetterAvatar::Identity.generate(name, SOME_SIZE)?


(Rafael dos Santos Silva) #2

You can write a plugin (maybe a pr?) that will allow you to use the first name char on the setting external system avatars url.

Currently it accepts: “Allowed substitutions are {username} {first_letter} {color} {size}”

Adding {name_first _letter} to that is the way to go.


(Jay Pfaffman) #3

Oh. So you’re saying that what I want is to be able to change external system avatars url to

/letter_avatar_proxy/v2/letter/{name_first_letter}/{color}/{size}.png

And that “all” I would have to do is make a PR that defined name_first_letter?

That seems “easy” if I knew where to find the file that defines those substitutions.


(Rafael dos Santos Silva) #4

(Jay Pfaffman) #5

OMG. I might actually submit a PR that doesn’t involve shell scripts.


(Rafael dos Santos Silva) #6

Well I would first start with a plugin, so you can get it immediately working.


(Jay Pfaffman) #7

But it seems like I could make a PR that involved about 2 lines of code, something like

u=User.find_by_username(username)
name = some stuff if that search fails or there's no name
...
url.gsub! "{name_first_letter", name[0].downcase
...

And it’d take me a Long Time to figure out how to make a plugin do that.

And it’d need to be a bit more complicated not not needlessly do a username lookup every time, so it might not be as easy a PR as I’d thought, so maybe I"ll have to figure out the plugin after all. :frowning:


(Jay Pfaffman) #9

I wouldn’t have thought it possible, but with your help, I did it!

Thanks, @falco!