Class: RedisCaptcha::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_captcha/image.rb

Instance Method Summary collapse

Constructor Details

#initialize(captcha_key) ⇒ Image

Returns a new instance of Image.



3
4
5
6
# File 'lib/redis_captcha/image.rb', line 3

def initialize(captcha_key)
  @key_handler = RedisCaptcha::KeyHandler.new(captcha_key)
  @options = RedisCaptcha.options
end

Instance Method Details

#content_typeObject



35
36
37
# File 'lib/redis_captcha/image.rb', line 35

def content_type
  @options[:content_type]
end

#filenameObject



31
32
33
# File 'lib/redis_captcha/image.rb', line 31

def filename
  "#{@options[:tempfile_name]}#{@options[:tempfile_type]}"
end

#generateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/redis_captcha/image.rb', line 8

def generate
  unless @key_handler.locked?
    @string = get_string
    @key_handler.set(@string)

    tempfile = Tempfile.new([@options[:tempfile_name], @options[:tempfile_type]], @options[:tempfile_path])

    params = ""
    params << get_line_param
    params << get_image_size_param
    params << get_background_param
    params << get_string_param
    params << get_swirl_param

    command = `#{@options[:image_magick_path]}convert #{params} #{tempfile.path}`
    puts "#{@options[:image_magick_path]}convert #{params} #{tempfile.path}"

    tempfile
  else
    nil
  end
end