Class: Captcher::TextImage

Inherits:
Object
  • Object
show all
Defined in:
lib/captcher/text_image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/captcher/text_image.rb', line 3

def config
  @config
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/captcher/text_image.rb', line 3

def text
  @text
end

Instance Method Details

#generateObject

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