Module: RmagickCaptcha::RmagickBackend

Defined in:
lib/rmagick_captcha/rmagick_backend.rb

Class Method Summary collapse

Class Method Details

.get_captcha_image(key, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rmagick_captcha/rmagick_backend.rb', line 6

def self.get_captcha_image (key, options = {})
  options = ::RmagickCaptcha.options.merge(options)
  canvas = ::Magick::Image.new(options[:gc_width], options[:gc_height],
    Magick::HatchFill.new('white','lightcyan2'))


  gc = ::Magick::Draw.new
  draw_text(key, gc, options)

  gc.push
  gc.fill('blue')
  gc.fill_opacity(0.3)
  gc.bezier(0,options[:gc_height],rand(40),rand(30),rand(options[:gc_width]),
            1,options[:gc_width],options[:gc_height])
  gc.pop

  gc.push
  gc.fill('green')
  gc.fill_opacity(0.4)
  gc.bezier(0,0,rand(10),rand(40)+20,rand(40)+20,rand(40)+20,options[:gc_width],0)
  gc.pop

  gc.draw(canvas)

  canvas.format= options[:img_format]
  return canvas.to_blob()
end