FEATURE: new letter avatars algorithm

This commit is contained in:
Régis Hanol 2015-06-02 16:33:18 +02:00
parent fa963e8f38
commit 1067cde0d0
1 changed files with 10 additions and 19 deletions

View File

@ -1,13 +1,13 @@
class LetterAvatar
# BUMP UP if avatar algorithm changes
VERSION = 3
VERSION = 4
# Largest avatar generated, one day when pixel ratio hit 3
# we will need to change this
FULLSIZE = 240
# CHANGE these values to support more pixel ratios
FULLSIZE = 120 * 3
POINTSIZE = 280
class<<self
class << self
class Identity
attr_accessor :color, :letter
@ -46,6 +46,7 @@ class LetterAvatar
generate_fullsize(identity) if !cache || !File.exists?(fullsize)
OptimizedImage.resize(fullsize, filename, size, size)
filename
end
end
@ -53,7 +54,6 @@ class LetterAvatar
def cached_path(identity, size)
dir = "#{cache_path}/#{identity.letter}/#{identity.color.join("_")}"
FileUtils.mkdir_p(dir)
"#{dir}/#{size}.png"
end
@ -66,18 +66,15 @@ class LetterAvatar
letter = identity.letter
filename = fullsize_path(identity)
stroke = darken(color, 0.8)
instructions = %W{
-size #{FULLSIZE}x#{FULLSIZE}
xc:#{to_rgb(color)}
-pointsize 180
-fill white
-gravity Center
-pointsize #{POINTSIZE}
-fill 'rgba(255,255,255,0.8)'
-font 'Helvetica'
-stroke #{to_rgb(stroke)}
-strokewidth 2
-annotate -0+20 '#{letter}'
-gravity Center
-annotate -0+26 '#{letter}'
-depth 8
'#{filename}'
}
@ -89,12 +86,6 @@ class LetterAvatar
filename
end
def darken(color,pct)
color.map do |n|
(n.to_f * pct).to_i
end
end
def to_rgb(color)
r,g,b = color
"'rgb(#{r},#{g},#{b})'"