Parent

Methods

Included Modules

Captcha::Image

Attributes

code[R]
data[R]

Public Class Methods

new(o) click to toggle source
# File lib/captcha/image.rb, line 9
def initialize(o)
  generate_code o

  canvas = Magick::Image.new(o[:dimensions][:width], o[:dimensions][:height]) {
    self.background_color = o[:colors][:background]
  }
  
  text = Magick::Draw.new
  text.font = File.expand_path o[:ttf]
  text.pointsize = o[:letters][:points]
  
  cur = 0
  @code.each { |c|
    text.annotate(canvas, 0, 0, cur, o[:letters][:baseline], c) {
      self.fill = o[:colors][:font]
    }
    cur += o[:letters][:width]
  }
  
  w = o[:wave][:wavelength]
  canvas = canvas.wave(o[:wave][:amplitude], rand(w.last - w.first) + w.first)
  canvas = canvas.implode(o[:implode])
  
  @code = @code.to_s
  @data = canvas.to_blob { self.format = "JPG" }
  canvas.destroy!
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.