avatarly 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/README.md +11 -0
- data/lib/avatarly.rb +7 -5
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d229c78d18e36061ec7628d50d786713f306cf3e
|
4
|
+
data.tar.gz: 54668761e1d7e58142d7f240050dd02fef727552
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12c846630066cc8f7f6b6f627e57e40bf22fef0095fbea99e99ac87bc38db4cdef453ac4c817420ae0c99b20f2b554f382c37c9a78fd94a943b6ad15b126e0f0
|
7
|
+
data.tar.gz: c2bea1a8b5aaeb50eeb4891420dab87d93974510398a17c98a5c014d1bc09dc1bb86b8851e1dd81e8fad0b193aeb8b4c4f116b93f5c82803656bf825b2d8d4d7
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
# avatarly
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/avatarly.png)](https://rubygems.org/gems/avatarly)
|
6
|
+
[![Build Status](https://travis-ci.org/lucek/avatarly.svg?branch=master)](https://travis-ci.org/lucek/avatarly)
|
7
|
+
|
5
8
|
avatarly is a simple gem for creating gmail-like user avatars based on user email or any other string passed
|
6
9
|
|
7
10
|
inspired and influenced by https://github.com/johnnyhalife/avatar-generator.rb
|
@@ -43,9 +46,17 @@ the only required parameter is <tt>text</tt>. Other options that you can pass ar
|
|
43
46
|
* <tt>size</tt> (default: 32)
|
44
47
|
* <tt>font</tt> (path to font - e.g. "#{Rails.root}/your_font.ttf")
|
45
48
|
* <tt>font_size</tt> (default: size / 2)
|
49
|
+
* <tt>format</tt> (default: png)
|
46
50
|
|
47
51
|
As a result you will get an image blob - rest is up to you, do whatever you want with it.
|
48
52
|
|
53
|
+
For instance you can store avatar in directory with images:
|
54
|
+
|
55
|
+
img = Avatarly.generate_avatar(text, opts={})
|
56
|
+
File.open('public/images/avatar_name.png', 'wb') do |f|
|
57
|
+
f.write img
|
58
|
+
end
|
59
|
+
|
49
60
|
## License
|
50
61
|
|
51
62
|
MIT
|
data/lib/avatarly.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'rvg/rvg'
|
2
2
|
require 'rfc822'
|
3
|
+
require 'pathname'
|
3
4
|
|
4
5
|
class Avatarly
|
5
|
-
BACKGROUND_COLORS = [
|
6
|
+
BACKGROUND_COLORS = [
|
6
7
|
"#ff4040", "#7f2020", "#cc5c33", "#734939", "#bf9c8f", "#995200",
|
7
8
|
"#4c2900", "#f2a200", "#ffd580", "#332b1a", "#4c3d00", "#ffee00",
|
8
9
|
"#b0b386", "#64664d", "#6c8020", "#c3d96c", "#143300", "#19bf00",
|
@@ -14,7 +15,7 @@ class Avatarly
|
|
14
15
|
|
15
16
|
class << self
|
16
17
|
def generate_avatar(text, opts={})
|
17
|
-
generate_image(initials(text.to_s).upcase, parse_options(opts)).to_blob
|
18
|
+
generate_image(initials(text.to_s.gsub(/\W/,'')).upcase, parse_options(opts)).to_blob
|
18
19
|
end
|
19
20
|
|
20
21
|
def root
|
@@ -35,7 +36,7 @@ class Avatarly
|
|
35
36
|
image = Magick::RVG.new(opts[:size], opts[:size]).viewbox(0, 0, opts[:size], opts[:size]) do |canvas|
|
36
37
|
canvas.background_fill = opts[:background_color]
|
37
38
|
end.draw
|
38
|
-
image.format =
|
39
|
+
image.format = opts[:format]
|
39
40
|
draw_text(image, text, opts)
|
40
41
|
image
|
41
42
|
end
|
@@ -50,7 +51,7 @@ class Avatarly
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def initials(text)
|
53
|
-
if text.
|
54
|
+
if text.is_email?
|
54
55
|
initials_for_separator(text.split("@").first, ".")
|
55
56
|
elsif text.include?(" ")
|
56
57
|
initials_for_separator(text, " ")
|
@@ -72,7 +73,8 @@ class Avatarly
|
|
72
73
|
{ background_color: BACKGROUND_COLORS.sample,
|
73
74
|
font_color: '#FFFFFF',
|
74
75
|
size: 32,
|
75
|
-
font: "#{fonts}/Roboto.ttf"
|
76
|
+
font: "#{fonts}/Roboto.ttf",
|
77
|
+
format: "png" }
|
76
78
|
end
|
77
79
|
|
78
80
|
def parse_options(opts)
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avatarly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukasz Odziewa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rfc822
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Avatarly is a simple gem for Ruby that creates gmail-like avatars with
|
@@ -45,11 +45,11 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- README.md
|
49
|
-
- LICENSE
|
50
48
|
- Gemfile
|
51
|
-
-
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
52
51
|
- assets/fonts/Roboto.ttf
|
52
|
+
- lib/avatarly.rb
|
53
53
|
homepage: https://github.com/lucek/avatarly
|
54
54
|
licenses:
|
55
55
|
- MIT
|
@@ -60,17 +60,17 @@ require_paths:
|
|
60
60
|
- lib
|
61
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
|
-
- -
|
63
|
+
- - ">="
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.
|
73
|
+
rubygems_version: 2.4.6
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Simple gem for creating gmail-like user avatars with initials.
|