Class: Captcher::TextImage
- Inherits:
-
Object
- Object
- Captcher::TextImage
- Defined in:
- lib/captcher/text_image.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#generate ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Lint/Void.
-
#initialize(text, config) ⇒ TextImage
constructor
A new instance of TextImage.
Constructor Details
#initialize(text, config) ⇒ TextImage
Returns a new instance of TextImage.
5 6 7 8 |
# File 'lib/captcher/text_image.rb', line 5 def initialize(text, config) @text = text @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/captcher/text_image.rb', line 3 def config @config end |
#text ⇒ Object
Returns the value of attribute text.
3 4 5 |
# File 'lib/captcher/text_image.rb', line 3 def text @text end |
Instance Method Details
#generate ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Lint/Void
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/captcher/text_image.rb', line 13 def generate MiniMagick::Tool::Convert.new do |i| i.font random_font i.size image_size i.pointsize config[:font_size] i.fill config[:font_color] i.gravity "center" i.canvas config[:background] i.draw "text 0,0 '#{text}'" i.noise + "Gaussian" i << "#{config[:format]}:-" end end |