class Captcher::TextImage
Attributes
config[RW]
text[RW]
Public Class Methods
new(text, config)
click to toggle source
# File lib/captcher/text_image.rb, line 5 def initialize(text, config) @text = text @config = config end
Public Instance Methods
generate()
click to toggle source
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Lint/Void
# 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
Private Instance Methods
image_height()
click to toggle source
# File lib/captcher/text_image.rb, line 36 def image_height config[:font_size] + 10 end
image_size()
click to toggle source
rubocop:enable Lint/Void rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize
# File lib/captcher/text_image.rb, line 32 def image_size "#{image_width}x#{image_height}" end
image_width()
click to toggle source
# File lib/captcher/text_image.rb, line 40 def image_width config[:font_size] * config[:count] + 10 end
random_font()
click to toggle source
# File lib/captcher/text_image.rb, line 44 def random_font config[:fonts].sample end