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.2'

Class Method Summary collapse

Methods included from Configuration

annotate_position, annotate_position=, cache_base_path, cache_base_path=, colors_palette, colors_palette=, fill_color, fill_color=, weight, weight=

Class Method Details

.execute(cmd) ⇒ Object



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

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



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

def self.generate(username, size)
  Avatar.generate(username, size)
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
37
# 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}
      -interpolate bicubic
      -unsharp 2x0.5+0.7+0
      -quality 98
      #{to}
    ).join(' ')
  )
  true
rescue
  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