letter_avatar 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +7 -2
- data/lib/letter_avatar/avatar.rb +14 -23
- data/lib/letter_avatar/avatar_helper.rb +10 -1
- data/lib/letter_avatar/colors.rb +1 -1
- data/lib/letter_avatar/version.rb +1 -1
- data/lib/letter_avatar.rb +31 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23085c33db8856b2c47db111f78212c2026b24a
|
4
|
+
data.tar.gz: 5dc1880d4338652bc95b9c660a7b21eef98e22f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da069e4393094434e4d5a899e56547bb2384f297b643df2ad7c244406986806c8f263d549206f67460cd010b8939552775f6baa360de084c158701343366728b
|
7
|
+
data.tar.gz: c40982c022892c56b00bbc8c93c8f6e83eeb4529a6607c72c2e8e4b8b0d5fd7c89bdbf643ff10d2dd6c4da4ed4bc641e6d598e4758efd0925dbcb47b89a32c57
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
+
0.1.10
|
2
|
+
-----
|
3
|
+
|
4
|
+
- `LetterAvatar::AvatarHelper` module tweaks
|
5
|
+
- `letter_avatar_url` method, returning avatar proper url
|
6
|
+
- `letter_avatar_tag` doeas not require `ActionView::Helpers::AssetTagHelper`
|
7
|
+
|
8
|
+
0.1.9
|
9
|
+
-----
|
10
|
+
|
11
|
+
- `LetterAvatar::Configuration` module, `mattr_accessor` (depending on `ActiveSupport`) removed
|
12
|
+
|
13
|
+
fixes [#7](https://github.com/ksz2k/letter_avatar/issues/7)
|
14
|
+
|
1
15
|
0.1.5
|
2
16
|
-----
|
3
17
|
|
4
18
|
- Use [posix-spawn](https://github.com/rtomayko/posix-spawn) to instead of Kernel#exec to get better performance.
|
19
|
+
|
5
20
|
> fork(2) calls slow down as the parent process uses more memory due to the need to copy page tables.
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# LetterAvatar
|
2
2
|
|
3
|
-
Gem for creating letter avatar from user's name.
|
3
|
+
Gem for creating letter avatar from user's name (or any other strong / character).
|
4
4
|
|
5
|
-
Code extracted from discourse source (thanks guys!) - I needed this functionality in three projects, so here's the gem! :-)
|
5
|
+
Code extracted from [discourse](https://www.discourse.org/) source (thanks guys!) - I needed this functionality in three projects, so here's the gem! :-)
|
6
6
|
|
7
7
|
[![Code Climate](https://codeclimate.com/github/ksz2k/letter_avatar/badges/gpa.svg)](https://codeclimate.com/github/ksz2k/letter_avatar)
|
8
8
|
|
@@ -82,8 +82,13 @@ There's also helper for this. To use it, you need:
|
|
82
82
|
|
83
83
|
```ruby
|
84
84
|
letter_avatar_for('ksz2k', 200)
|
85
|
+
=> "public/system/letter_avatars/2/K/87_178_230/200.png"
|
86
|
+
# or
|
87
|
+
letter_avatar_url('ksz2k', 200)
|
88
|
+
=> "/system/letter_avatars/2/K/87_178_230/200.png"
|
85
89
|
# or even
|
86
90
|
letter_avatar_tag('ksz2k', 200, class: 'av')
|
91
|
+
=> "<img class=\"av\" alt=\"ksz2k\" src=\"/system/letter_avatars/2/K/87_178_230/200.png\" />"
|
87
92
|
```
|
88
93
|
|
89
94
|
### Way to support non [a-z0-9] charsets
|
data/lib/letter_avatar/avatar.rb
CHANGED
@@ -64,31 +64,22 @@ module LetterAvatar
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def generate_fullsize(identity)
|
67
|
-
color = identity.color
|
68
|
-
letter = identity.letter
|
69
|
-
|
70
|
-
|
71
67
|
filename = fullsize_path(identity)
|
72
68
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
Process.waitpid(pid)
|
88
|
-
err = stderr.read
|
89
|
-
if err != nil && err.length > 0
|
90
|
-
raise "letter_avatar error: #{err.strip}"
|
91
|
-
end
|
69
|
+
LetterAvatar.execute(
|
70
|
+
%W(
|
71
|
+
convert
|
72
|
+
-size #{FULLSIZE}x#{FULLSIZE}
|
73
|
+
xc:#{to_rgb(identity.color)}
|
74
|
+
-pointsize 140
|
75
|
+
-font #{FONT_FILENAME}
|
76
|
+
-weight #{LetterAvatar.weight}
|
77
|
+
-fill '#{FILL_COLOR}'
|
78
|
+
-gravity Center
|
79
|
+
-annotate #{LetterAvatar.annotate_position} '#{identity.letter}'
|
80
|
+
'#{filename}'
|
81
|
+
).join(' ')
|
82
|
+
)
|
92
83
|
|
93
84
|
filename
|
94
85
|
end
|
@@ -10,8 +10,17 @@ module LetterAvatar
|
|
10
10
|
avatar_path.to_s.sub('public/','/')
|
11
11
|
end
|
12
12
|
|
13
|
+
def letter_avatar_url(name, size = 64)
|
14
|
+
letter_avatar_url_for(letter_avatar_for(name, size))
|
15
|
+
end
|
16
|
+
|
13
17
|
def letter_avatar_tag(name, size = 64, options = {})
|
14
|
-
|
18
|
+
if defined?(ActionView::Helpers::AssetTagHelper)
|
19
|
+
include ActionView::Helpers::AssetTagHelper
|
20
|
+
image_tag(letter_avatar_url(name, size), options.merge(alt: name))
|
21
|
+
else
|
22
|
+
"<img alt=\"#{name}\" class\"#{options.fetch(:class)}\" src=\"#{letter_avatar_url(name, size)}\" />"
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
26
|
end
|
data/lib/letter_avatar/colors.rb
CHANGED
@@ -4,7 +4,7 @@ module LetterAvatar
|
|
4
4
|
PALETTES = [:google, :iwanthue]
|
5
5
|
|
6
6
|
def self.for(username)
|
7
|
-
public_send("with_#{LetterAvatar.colors_palette}", username)
|
7
|
+
public_send("with_#{LetterAvatar.colors_palette}", username)
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.with_iwanthue(username)
|
data/lib/letter_avatar.rb
CHANGED
@@ -6,29 +6,31 @@ require "letter_avatar/avatar_helper"
|
|
6
6
|
module LetterAvatar
|
7
7
|
extend LetterAvatar::Configuration
|
8
8
|
|
9
|
+
class ExecutionError < StandardError; end
|
10
|
+
|
9
11
|
def self.setup(&block)
|
10
12
|
yield(self)
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.resize(from, to, width, height)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
begin
|
17
|
+
execute(
|
18
|
+
# NOTE: ORDER is important!
|
19
|
+
%W{
|
20
|
+
convert
|
21
|
+
#{from}
|
22
|
+
-background transparent
|
23
|
+
-gravity center
|
24
|
+
-thumbnail #{width}x#{height}^
|
25
|
+
-extent #{width}x#{height}
|
26
|
+
-interpolate bicubic
|
27
|
+
-unsharp 2x0.5+0.7+0
|
28
|
+
-quality 98
|
29
|
+
#{to}
|
30
|
+
}.join(" ")
|
31
|
+
)
|
30
32
|
true
|
31
|
-
|
33
|
+
rescue => e
|
32
34
|
false
|
33
35
|
end
|
34
36
|
end
|
@@ -37,4 +39,16 @@ module LetterAvatar
|
|
37
39
|
Avatar.generate(username, size)
|
38
40
|
end
|
39
41
|
|
42
|
+
def self.execute(cmd)
|
43
|
+
cmd = cmd.join(' ') if cmd.is_a?(Array)
|
44
|
+
pid, stdin, stdout, stderr = POSIX::Spawn.popen4(cmd)
|
45
|
+
Process.waitpid(pid)
|
46
|
+
err = stderr.read
|
47
|
+
if err != nil && err.length > 0
|
48
|
+
raise ExecutionError.new("letter_avatar execution error (when calling '#{cmd}'): '#{err.strip}'")
|
49
|
+
else
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
40
54
|
end
|