Module: Raptcha::Image

Defined in:
lib/raptcha.rb

Class Method Summary collapse

Class Method Details

.create(options = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/raptcha.rb', line 85

def create(options = {})
  options = Raptcha.normalize(options)

  word = options[:word] || options[:w]
  encrypted = options[:encrypted] || options[:e]
  word ||= Encryptor.decrypt(encrypted) if encrypted
  word ||= Raptcha.word
  word = word.split(%r"").join(" ").strip.upcase

  Image.for(word)
end

.for(word) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/raptcha.rb', line 97

def for(word)
  command = %W(
    convert
      -size '242x42'
      -strokewidth 1
      -gravity center
      -fill '#333'
      -family 'monoco'
      -pointsize 42
      -bordercolor white
      -border 10 
      -annotate "0x0" #{ word.inspect }
      -implode 0.2
      -strokewidth 10
      -draw 'line 5 25 295 25'
      -draw 'line 5 35 295 35'
      -wave '3x50'
      xc:white jpg:-
  )
  command = command.join(' ')
  IO.popen(command){|pipe| pipe.read}
end

.inline(options = {}) ⇒ Object



120
121
122
# File 'lib/raptcha.rb', line 120

def inline(options = {})
  Base64.encode64(create(options))
end