letter_avatar 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa5863d77b3303b2c3c3e980f8a36c5b5be56a7e
4
- data.tar.gz: 231c30256287ab8ba036ed2c5b572975709a4e22
3
+ metadata.gz: ffacda0ec7a8bf7d0e86472745adde948c04ea53
4
+ data.tar.gz: 990c67997bc36eba73bf5bb2fe9d0ba0203230e6
5
5
  SHA512:
6
- metadata.gz: d4a6faab9ef6f4573cea674c1be1b37ea7339c20689bcf53e96a6a2354071f19811de50a0566b13ee981dfe01f4293c8cc345e8c2c5f429edae7609c5ac87682
7
- data.tar.gz: a8f4b56a920aa3a6df72aa1ee8693a2ea7f1006d60d6e0ab82c5238dbb871569dfa7c8a656baf674c952a30952b927935f7356aa083a15e26a8ee7ccb5ca3450
6
+ metadata.gz: 81a98ac1cdd46c264c3a18747dcae2a0a55467af2527730021ebab41fb091cc7ef85595f73f8509ef142dba55e8801179cce0a7736824eca9308f1d1e8ea99c1
7
+ data.tar.gz: e22ecefb7ab1b1cc3809f525e2e03f2f0d4b07108063825d5f13ec15a551958f01bf052a617280d1468f806a126b4b0cfb93a9fa790b3f18ee07166533af7d8e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.3.7
2
+ -----
3
+
4
+ - added `LetterAvatar.custom_palette` config option.
5
+ - bumped `FULLSIZE` to 600.
6
+
1
7
  0.3.6
2
8
  -----
3
9
 
data/README.md CHANGED
@@ -61,12 +61,23 @@ end
61
61
 
62
62
  #### Color palette
63
63
 
64
- We have two color palettes implemented: `iwanthue` and `google`.
64
+ We have three color palettes implemented: `iwanthue`, `google` and `custom`.
65
65
 
66
66
  Each of them have different colors, but the `iwanthue` also differently calculates the color for specified username.
67
67
 
68
68
  The `google` selected will generate the same avatar for both, "Krzysiek" and "ksz2k" usernames given (both of them starts with letter "k"), but `iwanthue` will calculate it's md5 and then selects color, so there's huge chance that these usernames get different colors.
69
69
 
70
+ ##### Custom palette definition
71
+
72
+ You can define your own `custom` palette:
73
+
74
+ ```ruby
75
+ LetterAvatar.setup do |config|
76
+ config.colors_palette = :custom
77
+ config.custom_palette = [[120, 132, 205], [91, 149, 249], [72, 194, 249], [69, 208, 226]]
78
+ end
79
+ ```
80
+
70
81
  ## Usage
71
82
 
72
83
  ```ruby
@@ -5,7 +5,7 @@ module LetterAvatar
5
5
 
6
6
  # Largest avatar generated, one day when pixel ratio hit 3
7
7
  # we will need to change this
8
- FULLSIZE = 240
8
+ FULLSIZE = 600
9
9
 
10
10
  FILL_COLOR = 'rgba(255, 255, 255, 0.65)'.freeze
11
11
 
@@ -43,7 +43,7 @@ module LetterAvatar
43
43
  fullsize = fullsize_path(identity)
44
44
  generate_fullsize(identity) if !cache || !File.exist?(fullsize)
45
45
 
46
- LetterAvatar.resize(fullsize, filename, size, size)
46
+ LetterAvatar.resize(fullsize, filename, size, size) if size != FULLSIZE
47
47
  filename
48
48
  end
49
49
 
@@ -1,6 +1,6 @@
1
1
  module LetterAvatar
2
2
  module Colors
3
- PALETTES = [:google, :iwanthue]
3
+ PALETTES = [:google, :iwanthue, :custom]
4
4
 
5
5
  GOOGLE_COLORS = [
6
6
  [226, 95, 81], # A
@@ -274,6 +274,19 @@ module LetterAvatar
274
274
  end
275
275
  end
276
276
 
277
+ def self.with_custom(username)
278
+ custom_palette = LetterAvatar.custom_palette
279
+ custom_palette[Digest::MD5.hexdigest(username)[0...15].to_i(16) % custom_palette.length]
280
+ end
281
+
282
+ def self.valid_custom_palette?(palette)
283
+ return false unless palette.is_a?(Array)
284
+ return palette.all? do |color|
285
+ false unless color.is_a?(Array)
286
+ color.all? { |i| i.is_a?(Integer) }
287
+ end
288
+ end
289
+
277
290
  # Colors form Google Inbox
278
291
  # https://inbox.google.com
279
292
  def self.google
@@ -21,9 +21,19 @@ module LetterAvatar
21
21
  end
22
22
 
23
23
  def colors_palette=(v)
24
- @colors_palette = v if v.in?(Colors::PALETTES)
24
+ @colors_palette = v if Colors::PALETTES.include?(v)
25
25
  end
26
26
 
27
+ def custom_palette
28
+ @custom_palette ||= nil
29
+ end
30
+
31
+ def custom_palette=(v)
32
+ @custom_palette = v
33
+ raise "Missing Custom Palette, please set config.custom_palette if using :custom" if @custom_palette.nil? && @colors_palette == :custom
34
+ raise "Invalid Custom Palette, please update config.custom_palette" unless Colors::valid_custom_palette?(@custom_palette)
35
+ end
36
+
27
37
  def weight
28
38
  @weight ||= 300
29
39
  end
@@ -1,3 +1,3 @@
1
1
  module LetterAvatar
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_avatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Discourse Developers
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-05-12 00:00:00.000000000 Z
14
+ date: 2019-02-05 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: Gem for creating letter avatar from user's name
17
17
  email:
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 2.6.10
53
+ rubygems_version: 2.6.14
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Create nice initals avatars from your users usernames