Module: ReallySimpleCaptcha::Captcha::PlainCaptcha
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/really_simple_captcha/captcha/plain_captcha.rb
Defined Under Namespace
Modules: ControllerHelpers, ViewHelpers
Constant Summary
collapse
- DEFAULT_OPTIONS =
{
width: 120,
height: 40,
wave_amplitude: 4.0,
wave_length: 60.0,
implode_amount: 0.3,
pointsize: 22,
text_fill: 'darkblue',
background_color: 'white'
}
Class Method Summary
collapse
Class Method Details
34
35
36
|
# File 'lib/really_simple_captcha/captcha/plain_captcha.rb', line 34
def self.configure(&block)
yield config
end
|
.generate_image(captcha_text, args = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/really_simple_captcha/captcha/plain_captcha.rb', line 65
def self.generate_image(captcha_text, args={})
options = DEFAULT_OPTIONS.merge(args)
image = ::Magick::Image.new(options[:width], options[:height]) do
self.background_color = options[:background_color]
end
text = ::Magick::Draw.new do
self.pointsize = options[:pointsize]
self.gravity = ::Magick::CenterGravity
self.fill = options[:text_fill]
end
text.annotate(image, 0, 0, 0, 0, captcha_text)
image = image.implode(options[:implode_amount]).wave(options[:wave_amplitude], options[:wave_length])
Base64.strict_encode64(image.to_blob { self.format = 'GIF' })
end
|