mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: SVG letter avatars (based on @eviltrout's spike)
This commit is contained in:
parent
36abc6f9f7
commit
cd77465788
8 changed files with 51 additions and 28 deletions
|
@ -7,20 +7,20 @@ class LetterAvatar
|
|||
FULLSIZE = 120 * 3
|
||||
POINTSIZE = 280
|
||||
|
||||
class << self
|
||||
class Identity
|
||||
attr_accessor :color, :letter
|
||||
|
||||
class Identity
|
||||
attr_accessor :color, :letter
|
||||
|
||||
def self.from_username(username)
|
||||
identity = new
|
||||
identity.color = LetterAvatar::COLORS[
|
||||
Digest::MD5.hexdigest(username)[0...15].to_i(16) % LetterAvatar::COLORS.length
|
||||
]
|
||||
identity.letter = username[0].upcase
|
||||
identity
|
||||
end
|
||||
def self.from_username(username)
|
||||
identity = new
|
||||
identity.color = LetterAvatar::COLORS[
|
||||
Digest::MD5.hexdigest(username)[0...15].to_i(16) % LetterAvatar::COLORS.length
|
||||
]
|
||||
identity.letter = username[0].upcase
|
||||
identity
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
|
||||
def version
|
||||
"#{VERSION}_#{image_magick_version}"
|
||||
|
@ -32,7 +32,7 @@ class LetterAvatar
|
|||
|
||||
def generate(username, size, opts = nil)
|
||||
DistributedMutex.synchronize("letter_avatar_#{version}_#{username}") do
|
||||
identity = Identity.from_username(username)
|
||||
identity = LetterAvatar::Identity.from_username(username)
|
||||
|
||||
cache = true
|
||||
cache = false if opts && opts[:cache] == false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue