Module: LetterAvatar

Extended by:
Configuration
Defined in:
lib/letter_avatar.rb,
lib/letter_avatar/avatar.rb,
lib/letter_avatar/colors.rb,
lib/letter_avatar/version.rb,
lib/letter_avatar/has_avatar.rb,
lib/letter_avatar/avatar_helper.rb,
lib/letter_avatar/configuration.rb

Defined Under Namespace

Modules: AvatarHelper, Colors, Configuration, HasAvatar Classes: Avatar, ExecutionError

Constant Summary collapse

VERSION =
'0.3.9'

Class Method Summary collapse

Methods included from Configuration

annotate_position, annotate_position=, cache_base_path, cache_base_path=, colors_palette, colors_palette=, custom_palette, custom_palette=, fill_color, fill_color=, font, font=, letters_count, letters_count=, pointsize, pointsize=, weight, weight=

Class Method Details

.execute(cmd) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/letter_avatar.rb', line 42

def self.execute(cmd)
  cmd = cmd.join(' ') if cmd.is_a?(Array)
  if Gem.win_platform?
    cmd.tr!("'", '"')
  end

  _stdout_str, err = Open3.capture3(cmd)
  if !err.nil? && !err.empty?
    raise ExecutionError.new("letter_avatar execution error (when calling '#{cmd}'): '#{err.strip}'")
  end

  true
end

.generate(username, size) ⇒ Object



38
39
40
# File 'lib/letter_avatar.rb', line 38

def self.generate(username, size)
  Avatar.generate(username, size)
end

.path_to_url(path) ⇒ Object



56
57
58
# File 'lib/letter_avatar.rb', line 56

def self.path_to_url(path)
  path.to_s.sub('public/', '/')
end

.resize(from, to, width, height) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/letter_avatar.rb', line 18

def self.resize(from, to, width, height)
  execute(
    # NOTE: ORDER is important!
    %W(
      convert
      #{from}
      -background transparent
      -gravity center
      -thumbnail #{width}x#{height}^
      -extent #{width}x#{height}
      -unsharp 2x0.5+0.7+0
      -quality 98
      #{to}
    ).join(' ')
  )
  true
rescue => e
  false
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (LetterAvatar)

    the object that the method was called on



14
15
16
# File 'lib/letter_avatar.rb', line 14

def self.setup(&_block)
  yield(self)
end