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.1.11"

Class Method Summary collapse

Methods included from Configuration

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

Class Method Details

.execute(cmd) ⇒ Object



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

def self.execute(cmd)
  cmd = cmd.join(' ') if cmd.is_a?(Array)
  if Gem.win_platform?
    require "open3"
    _stdout_str, err = Open3.capture3(cmd.tr("'", '"'))
  else
    pid, _stdin, _stdout, stderr = POSIX::Spawn.popen4(cmd)
    Process.waitpid(pid)
    err = stderr.read
  end
  if err != nil && err.length > 0
    raise ExecutionError.new("letter_avatar execution error (when calling '#{cmd}'): '#{err.strip}'")
  else
    true
  end
end

.generate(username, size) ⇒ Object



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

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

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



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

def self.resize(from, to, width, height)
  begin
    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 => e
    false
  end
end

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

Yields:

  • (_self)

Yield Parameters:

  • _self (LetterAvatar)

    the object that the method was called on



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

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