letter_avatar 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +12 -1
- data/lib/letter_avatar/avatar.rb +2 -2
- data/lib/letter_avatar/colors.rb +14 -1
- data/lib/letter_avatar/configuration.rb +11 -1
- data/lib/letter_avatar/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffacda0ec7a8bf7d0e86472745adde948c04ea53
|
|
4
|
+
data.tar.gz: 990c67997bc36eba73bf5bb2fe9d0ba0203230e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 81a98ac1cdd46c264c3a18747dcae2a0a55467af2527730021ebab41fb091cc7ef85595f73f8509ef142dba55e8801179cce0a7736824eca9308f1d1e8ea99c1
|
|
7
|
+
data.tar.gz: e22ecefb7ab1b1cc3809f525e2e03f2f0d4b07108063825d5f13ec15a551958f01bf052a617280d1468f806a126b4b0cfb93a9fa790b3f18ee07166533af7d8e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -61,12 +61,23 @@ end
|
|
|
61
61
|
|
|
62
62
|
#### Color palette
|
|
63
63
|
|
|
64
|
-
We have
|
|
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
|
data/lib/letter_avatar/avatar.rb
CHANGED
|
@@ -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 =
|
|
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
|
|
data/lib/letter_avatar/colors.rb
CHANGED
|
@@ -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
|
|
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
|
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.
|
|
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:
|
|
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.
|
|
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
|