avatarly 1.4.0 → 1.6.1

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.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +2 -0
  3. data/lib/avatarly.rb +15 -12
  4. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f0081142c330446d431cfbdec11ce81263a2fb0c
4
- data.tar.gz: ec658cc5995209171711dfedb97917efc07a2701
2
+ SHA256:
3
+ metadata.gz: 0e04398f6f8f9c7313396db8eb31fbdc9c29370d09e9a6ecc4ec72fdc1abcb47
4
+ data.tar.gz: 3333588aafd7b47928a02bfea20a5267545ea61448d4297ebb5911ef7a82acb4
5
5
  SHA512:
6
- metadata.gz: 2983b2c752403541f9091819de7cda4133d9aad53720a911f1ea3abd68bbea670de71b16e739b11ef4cc8ea7cb05ece3ca4d0b1bfd249214128ec5d037362cb7
7
- data.tar.gz: 6f1a26653ea8d2ee3a3c878a894e20411dd87b4fc16c28de967a778f0092fac5864d2442a41d15e6f3d56087c5c29b2f593a75cd1f1fb86dea432237043e75d0
6
+ metadata.gz: 9823d7ff979e7094a218d2556f996d716f22db76846885b8931c52f99eb1e33e54f26db31feb5e3954f39b12f1806205b96c2dab32daad80bd1a74aea5bafc24
7
+ data.tar.gz: 12c01d3bc079ade9ffc9fe56ad5bb047e440502201db62e6af09593ad84061608af44a58b40967636674c39dd265983874a605bfb3c21602cb93421bd839d28a
data/README.md CHANGED
@@ -50,8 +50,10 @@ the only required parameter is <tt>text</tt>. Other options that you can pass ar
50
50
  * <tt>size</tt> (default: 32)
51
51
  * <tt>font</tt> (path to font - e.g. "#{Rails.root}/your_font.ttf")
52
52
  * <tt>font_size</tt> (default: size / 2)
53
+ * <tt>vertical_offset</tt> (default: 0)
53
54
  * <tt>format</tt> (default: png)
54
55
  * <tt>lang</tt> (language code if unicode aware upcase required - e.g: :tr, default: nil)
56
+ * <tt>separator</tt> (the custom string or regex used to split <tt>text</tt> into its initials)
55
57
 
56
58
  As a result you will get an image blob - rest is up to you, do whatever you want with it.
57
59
 
data/lib/avatarly.rb CHANGED
@@ -17,9 +17,9 @@ class Avatarly
17
17
  class << self
18
18
  def generate_avatar(text, opts={})
19
19
  if opts[:lang]
20
- text = UnicodeUtils.upcase(initials(text.to_s.strip.gsub(/[^[[:word:]] ]/,'')), opts[:lang])
20
+ text = UnicodeUtils.upcase(initials(text.to_s.gsub(/[^[[:word:]] ]/,'').strip, opts), opts[:lang])
21
21
  else
22
- text = initials(text.to_s.strip.gsub(/[^\w ]/,'')).upcase
22
+ text = initials(text.to_s.gsub(/[^\w ]/,'').strip, opts).upcase
23
23
  end
24
24
  generate_image(text, parse_options(opts)).to_blob
25
25
  end
@@ -48,16 +48,18 @@ class Avatarly
48
48
  end
49
49
 
50
50
  def draw_text(canvas, text, opts)
51
- Magick::Draw.new do
52
- self.pointsize = opts[:font_size]
53
- self.font = opts[:font]
54
- self.fill = opts[:font_color]
55
- self.gravity = Magick::CenterGravity
56
- end.annotate(canvas, 0, 0, 0, 0, text)
51
+ Magick::Draw.new do |md|
52
+ md.pointsize = opts[:font_size]
53
+ md.font = opts[:font]
54
+ md.fill = opts[:font_color]
55
+ md.gravity = Magick::CenterGravity
56
+ end.annotate(canvas, 0, 0, 0, opts[:vertical_offset], text)
57
57
  end
58
58
 
59
- def initials(text)
60
- if text.is_email?
59
+ def initials(text, opts)
60
+ if opts[:separator]
61
+ initials_for_separator(text, opts[:separator])
62
+ elsif text.is_email?
61
63
  initials_for_separator(text.split("@").first, ".")
62
64
  elsif text.include?(" ")
63
65
  initials_for_separator(text, " ")
@@ -68,8 +70,7 @@ class Avatarly
68
70
 
69
71
  def initials_for_separator(text, separator)
70
72
  if text.include?(separator)
71
- text = text.split(separator)
72
- text[0][0] + text[1][0]
73
+ text.split(separator).compact.map{|part| part[0]}.join
73
74
  else
74
75
  text[0] || ''
75
76
  end
@@ -79,6 +80,7 @@ class Avatarly
79
80
  { background_color: BACKGROUND_COLORS.sample,
80
81
  font_color: '#FFFFFF',
81
82
  size: 32,
83
+ vertical_offset: 0,
82
84
  font: "#{fonts}/Roboto.ttf",
83
85
  format: "png" }
84
86
  end
@@ -89,6 +91,7 @@ class Avatarly
89
91
  opts[:font] = default_options[:font] unless Pathname(opts[:font]).exist?
90
92
  opts[:font_size] ||= opts[:size] / 2
91
93
  opts[:font_size] = opts[:font_size].to_i
94
+ opts[:vertical_offset] = opts[:vertical_offset].to_i
92
95
  opts
93
96
  end
94
97
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avatarly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukasz Odziewa
8
- autorequire:
8
+ - Artur Trzop
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-11-28 00:00:00.000000000 Z
12
+ date: 2021-10-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rmagick
@@ -68,7 +69,7 @@ homepage: https://github.com/lucek/avatarly
68
69
  licenses:
69
70
  - MIT
70
71
  metadata: {}
71
- post_install_message:
72
+ post_install_message:
72
73
  rdoc_options: []
73
74
  require_paths:
74
75
  - lib
@@ -83,9 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  - !ruby/object:Gem::Version
84
85
  version: '0'
85
86
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 2.4.5.1
88
- signing_key:
87
+ rubygems_version: 3.2.22
88
+ signing_key:
89
89
  specification_version: 4
90
90
  summary: Simple gem for creating gmail-like user avatars with initials.
91
91
  test_files: []