Commit 3ae1ad90d749b1926f4e0bf5da9ec407859a77f5
Committed by
GitHub
Exists in
master
Merge pull request #13 from aafaq-hassan/master
letter_count and pointsize configurations added
Showing
5 changed files
with
28 additions
and
3 deletions
Show diff stats
CHANGELOG.md
README.md
@@ -54,6 +54,8 @@ LetterAvatar.setup do |config| | @@ -54,6 +54,8 @@ LetterAvatar.setup do |config| | ||
54 | config.colors_palette = :iwanthue # default is :google | 54 | config.colors_palette = :iwanthue # default is :google |
55 | config.weight = 500 # default is 300 | 55 | config.weight = 500 # default is 300 |
56 | config.annotate_position = '-0+10' # default is -0+5 | 56 | config.annotate_position = '-0+10' # default is -0+5 |
57 | + config.letters_count = 2 # default is 1 | ||
58 | + config.pointsize = 70 # default is 140 | ||
57 | end | 59 | end |
58 | ``` | 60 | ``` |
59 | 61 |
lib/letter_avatar/avatar.rb
@@ -18,7 +18,8 @@ module LetterAvatar | @@ -18,7 +18,8 @@ module LetterAvatar | ||
18 | def self.from_username(username) | 18 | def self.from_username(username) |
19 | identity = new | 19 | identity = new |
20 | identity.color = LetterAvatar::Colors.for(username) | 20 | identity.color = LetterAvatar::Colors.for(username) |
21 | - identity.letter = username[0].upcase | 21 | + letters = username.split(/\s+/).map {|word| word[0]}.join('')[0..LetterAvatar.letters_count - 1] |
22 | + identity.letter = letters.upcase | ||
22 | 23 | ||
23 | identity | 24 | identity |
24 | end | 25 | end |
@@ -65,7 +66,7 @@ module LetterAvatar | @@ -65,7 +66,7 @@ module LetterAvatar | ||
65 | convert | 66 | convert |
66 | -size #{FULLSIZE}x#{FULLSIZE} | 67 | -size #{FULLSIZE}x#{FULLSIZE} |
67 | xc:#{to_rgb(identity.color)} | 68 | xc:#{to_rgb(identity.color)} |
68 | - -pointsize 140 | 69 | + -pointsize #{LetterAvatar.pointsize} |
69 | -font #{FONT_FILENAME} | 70 | -font #{FONT_FILENAME} |
70 | -weight #{LetterAvatar.weight} | 71 | -weight #{LetterAvatar.weight} |
71 | -fill '#{LetterAvatar.fill_color}' | 72 | -fill '#{LetterAvatar.fill_color}' |
lib/letter_avatar/configuration.rb
@@ -39,5 +39,21 @@ module LetterAvatar | @@ -39,5 +39,21 @@ module LetterAvatar | ||
39 | def annotate_position=(v) | 39 | def annotate_position=(v) |
40 | @annotate_position = v | 40 | @annotate_position = v |
41 | end | 41 | end |
42 | + | ||
43 | + def letters_count | ||
44 | + @letters_count ||= 1 | ||
45 | + end | ||
46 | + | ||
47 | + def letters_count=(v) | ||
48 | + @letters_count = v | ||
49 | + end | ||
50 | + | ||
51 | + def pointsize | ||
52 | + @pointsize ||= 140 | ||
53 | + end | ||
54 | + | ||
55 | + def pointsize=(v) | ||
56 | + @pointsize = v | ||
57 | + end | ||
42 | end | 58 | end |
43 | end | 59 | end |
lib/letter_avatar/version.rb