Commit 2f5d91bada07263a2868060acac83be83fabf7f8

Authored by Krzysiek Szczuka
2 parents 255e9eca 5ee9619c
Exists in master

Merge pull request #4 from ksz2k/google-inbox-avatar-style

Change colors to same like Google Inbox avatar.
README.md
... ... @@ -8,8 +8,7 @@ Code extracted from discourse source (thanks guys!) - I needed this functionalit
8 8  
9 9 ## Examples
10 10  
11   -![y](https://cloud.githubusercontent.com/assets/5518/11026688/5de280c0-86e8-11e5-927c-361f3becbf08.png) ![x](https://cloud.githubusercontent.com/assets/5518/11026687/5dddcf08-86e8-11e5-9b94-d691e6b4af9e.png) ![s](https://cloud.githubusercontent.com/assets/5518/11026690/5e2ae2d4-86e8-11e5-938e-b954aa7810f6.png) ![r](https://cloud.githubusercontent.com/assets/5518/11026689/5e292a48-86e8-11e5-9bc5-58b58341203a.png) ![n](https://cloud.githubusercontent.com/assets/5518/11026691/5e73c8f0-86e8-11e5-81ae-9d1ba96f3ea8.png) ![m](https://cloud.githubusercontent.com/assets/5518/11026692/5e73a71c-86e8-11e5-8c3a-752fa606ce98.png) ![l](https://cloud.githubusercontent.com/assets/5518/11026694/5eae94b2-86e8-11e5-9be7-9ac13b1e068e.png) ![j](https://cloud.githubusercontent.com/assets/5518/11026693/5eae0092-86e8-11e5-95e7-c4417e405776.png)
12   -
  11 +![a](https://cloud.githubusercontent.com/assets/5518/11028712/fb4ceb8a-86fb-11e5-8a94-c75eaf46b089.png) ![b](https://cloud.githubusercontent.com/assets/5518/11028713/fb55fc5c-86fb-11e5-9a67-a4e84ee618be.png) ![c](https://cloud.githubusercontent.com/assets/5518/11028715/fb5a8178-86fb-11e5-9312-9cc990b1a94f.png) ![d](https://cloud.githubusercontent.com/assets/5518/11028714/fb567f88-86fb-11e5-8e99-b14602321f69.png) ![e](https://cloud.githubusercontent.com/assets/5518/11028716/fb61d194-86fb-11e5-8bab-bc69cad905cc.png) ![f](https://cloud.githubusercontent.com/assets/5518/11028717/fb656d54-86fb-11e5-810a-f8a3847c0da8.png) ![g](https://cloud.githubusercontent.com/assets/5518/11028718/fb862e7c-86fb-11e5-8b46-42a64fb15f46.png) ![h](https://cloud.githubusercontent.com/assets/5518/11028719/fb8f1910-86fb-11e5-9794-433a9490b15a.png) ![j](https://cloud.githubusercontent.com/assets/5518/11028720/fb8f200e-86fb-11e5-8b20-476745abfe21.png) ![l](https://cloud.githubusercontent.com/assets/5518/11028721/fb923654-86fb-11e5-961c-92be1aaedef8.png) ![m](https://cloud.githubusercontent.com/assets/5518/11028722/fb9e68b6-86fb-11e5-8ba6-4e8ece3a9d89.png) ![n](https://cloud.githubusercontent.com/assets/5518/11028723/fba26826-86fb-11e5-9611-bde4bc7d84ed.png) ![p](https://cloud.githubusercontent.com/assets/5518/11028724/fbc4d9ec-86fb-11e5-85f3-0e0b46bbc9a1.png) ![s](https://cloud.githubusercontent.com/assets/5518/11028725/fbc5d464-86fb-11e5-937e-de11c747b70d.png)
13 12  
14 13 ## Installation
15 14  
... ...
Roboto-Medium 0 → 100644
No preview for this file type
letter_avatar.gemspec
... ... @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15 15  
16 16 spec.rubyforge_project = "letter_avatar"
17 17  
18   - spec.files = `git ls-files`.split($/)
  18 + spec.files = `git ls-files`.split($/) + ['Roboto-Medium']
19 19 spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20 20 spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21 21 spec.require_paths = ["lib"]
... ...
lib/letter_avatar/avatar.rb
... ... @@ -69,10 +69,12 @@ module LetterAvatar
69 69 instructions = %W{
70 70 -size 240x240
71 71 xc:#{to_rgb(color)}
72   - -pointsize 150
  72 + -pointsize 140
  73 + -font Roboto-Medium
  74 + -weight 500
73 75 -fill '#{FILL_COLOR}'
74 76 -gravity Center
75   - -annotate -5+20 '#{letter}'
  77 + -annotate -0+10 '#{letter}'
76 78 '#{filename}'
77 79 }
78 80  
... ...
lib/letter_avatar/colors.rb
1 1 module LetterAvatar
2 2 module Colors
3 3  
  4 + # Colors form Google Inbox
  5 + # https://inbox.google.com
  6 + COLORS = [
  7 + [226, 95, 81], # A
  8 + [242, 96, 145], # B
  9 + [187, 101, 202], # C
  10 + [149, 114, 207], # D
  11 + [120, 132, 205], # E
  12 + [91, 149, 249], # F
  13 + [72, 194, 249], # G
  14 + [69, 208, 226], # H
  15 + [72, 182, 172], # I
  16 + [82, 188, 137], # J
  17 + [155, 206, 95], # K
  18 + [212, 227, 74], # L
  19 + [254, 218, 16], # M
  20 + [247, 192, 0], # N
  21 + [255, 168, 0], # O
  22 + [255, 138, 96], # P
  23 + [194, 194, 194], # Q
  24 + [143, 164, 175], # R
  25 + [162, 136, 126], # S
  26 + [163, 163, 163], # T
  27 + [175, 181, 226], # U
  28 + [179, 155, 221], # V
  29 + [194, 194, 194], # W
  30 + [124, 222, 235], # X
  31 + [188, 170, 164], # Y
  32 + [173, 214, 125] # Z
  33 + ]
  34 +
4 35 def self.for(username)
5   - all[
6   - Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length
7   - ]
  36 + char = username[0]
  37 + char.upcase!
  38 + if /[A-Z]/.match(char)
  39 + # 65 is 'A' ord
  40 + idx = char.ord - 65
  41 + return all[idx]
  42 + end
  43 +
  44 + if /[\d]/.match(char)
  45 + return all[char.to_i]
  46 + end
  47 +
  48 + all[Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length]
8 49 end
9 50  
10   - # palette of optimally disctinct colors
11   - # cf. http://tools.medialab.sciences-po.fr/iwanthue/index.php
12   - # parameters used:
13   - # - H: 0 - 360
14   - # - C: 0 - 2
15   - # - L: 0.75 - 1.5
16 51 def self.all
17   - [
18   - [198,125,40],
19   - [61,155,243],
20   - [74,243,75],
21   - [238,89,166],
22   - [52,240,224],
23   - [177,156,155],
24   - [240,120,145],
25   - [111,154,78],
26   - [237,179,245],
27   - [237,101,95],
28   - [89,239,155],
29   - [43,254,70],
30   - [163,212,245],
31   - [65,152,142],
32   - [165,135,246],
33   - [181,166,38],
34   - [187,229,206],
35   - [77,164,25],
36   - [179,246,101],
37   - [234,93,37],
38   - [225,155,115],
39   - [142,140,188],
40   - [223,120,140],
41   - [249,174,27],
42   - [244,117,225],
43   - [137,141,102],
44   - [75,191,146],
45   - [188,239,142],
46   - [164,199,145],
47   - [173,120,149],
48   - [59,195,89],
49   - [222,198,220],
50   - [68,145,187],
51   - [236,204,179],
52   - [159,195,72],
53   - [188,121,189],
54   - [166,160,85],
55   - [181,233,37],
56   - [236,177,85],
57   - [121,147,160],
58   - [234,218,110],
59   - [241,157,191],
60   - [62,200,234],
61   - [133,243,34],
62   - [88,149,110],
63   - [59,228,248],
64   - [183,119,118],
65   - [251,195,45],
66   - [113,196,122],
67   - [197,115,70],
68   - [80,175,187],
69   - [103,231,238],
70   - [240,72,133],
71   - [228,149,241],
72   - [180,188,159],
73   - [172,132,85],
74   - [180,135,251],
75   - [236,194,58],
76   - [217,176,109],
77   - [88,244,199],
78   - [186,157,239],
79   - [113,230,96],
80   - [206,115,165],
81   - [244,178,163],
82   - [230,139,26],
83   - [241,125,89],
84   - [83,160,66],
85   - [107,190,166],
86   - [197,161,210],
87   - [198,203,245],
88   - [238,117,19],
89   - [228,119,116],
90   - [131,156,41],
91   - [145,178,168],
92   - [139,170,220],
93   - [233,95,125],
94   - [87,178,230],
95   - [157,200,119],
96   - [237,140,76],
97   - [229,185,186],
98   - [144,206,212],
99   - [236,209,158],
100   - [185,189,79],
101   - [34,208,66],
102   - [84,238,129],
103   - [133,140,134],
104   - [67,157,94],
105   - [168,179,25],
106   - [140,145,240],
107   - [151,241,125],
108   - [67,162,107],
109   - [200,156,21],
110   - [169,173,189],
111   - [226,116,189],
112   - [133,231,191],
113   - [194,161,63],
114   - [241,77,99],
115   - [241,217,53],
116   - [123,204,105],
117   - [210,201,119],
118   - [229,108,155],
119   - [240,91,72],
120   - [187,115,210],
121   - [240,163,100],
122   - [178,217,57],
123   - [179,135,116],
124   - [204,211,24],
125   - [186,135,57],
126   - [223,176,135],
127   - [204,148,151],
128   - [116,223,50],
129   - [95,195,46],
130   - [123,160,236],
131   - [181,172,131],
132   - [142,220,202],
133   - [240,140,112],
134   - [172,145,164],
135   - [228,124,45],
136   - [135,151,243],
137   - [42,205,125],
138   - [192,233,116],
139   - [119,170,114],
140   - [158,138,26],
141   - [73,190,183],
142   - [185,229,243],
143   - [227,107,55],
144   - [196,205,202],
145   - [132,143,60],
146   - [233,192,237],
147   - [62,150,220],
148   - [205,201,141],
149   - [106,140,190],
150   - [161,131,205],
151   - [135,134,158],
152   - [198,139,81],
153   - [115,171,32],
154   - [101,181,67],
155   - [149,137,119],
156   - [37,142,183],
157   - [183,130,175],
158   - [168,125,133],
159   - [124,142,87],
160   - [236,156,171],
161   - [232,194,91],
162   - [219,200,69],
163   - [144,219,34],
164   - [219,95,187],
165   - [145,154,217],
166   - [165,185,100],
167   - [127,238,163],
168   - [224,178,198],
169   - [119,153,120],
170   - [124,212,92],
171   - [172,161,105],
172   - [231,155,135],
173   - [157,132,101],
174   - [122,185,146],
175   - [53,166,51],
176   - [70,163,90],
177   - [150,190,213],
178   - [210,107,60],
179   - [166,152,185],
180   - [159,194,159],
181   - [39,141,222],
182   - [202,176,161],
183   - [95,140,229],
184   - [168,142,87],
185   - [93,170,203],
186   - [159,142,54],
187   - [14,168,39],
188   - [94,150,149],
189   - [187,206,136],
190   - [157,224,166],
191   - [235,158,208],
192   - [109,232,216],
193   - [141,201,87],
194   - [208,124,118],
195   - [142,125,214],
196   - [19,237,174],
197   - [72,219,41],
198   - [234,102,111],
199   - [168,142,79],
200   - [188,135,35],
201   - [95,155,143],
202   - [148,173,116],
203   - [223,112,95],
204   - [228,128,236],
205   - [206,114,54],
206   - [195,119,88],
207   - [235,140,94],
208   - [235,202,125],
209   - [233,155,153],
210   - [214,214,238],
211   - [246,200,35],
212   - [151,125,171],
213   - [132,145,172],
214   - [131,142,118],
215   - [199,126,150],
216   - [61,162,123],
217   - [58,176,151],
218   - [215,141,69],
219   - [225,154,220],
220   - [220,77,167],
221   - [233,161,64],
222   - [130,221,137],
223   - [81,191,129],
224   - [169,162,140],
225   - [174,177,222],
226   - [236,174,47],
227   - [233,188,180],
228   - [69,222,172],
229   - [71,232,93],
230   - [118,211,238],
231   - [157,224,83],
232   - [218,105,73],
233   - [126,169,36]
234   - ]
  52 + COLORS
235 53 end
236 54  
237 55 end
... ...
lib/letter_avatar/version.rb
1 1 module LetterAvatar
2   - VERSION = "0.0.9"
  2 + VERSION = "0.1.0"
3 3 end
... ...