Module: SimpleCaptcha::ImageHelpers

Included in:
Middleware
Defined in:
lib/simple_captcha/image.rb

Overview

:nodoc

Defined Under Namespace

Classes: Tempfile

Constant Summary collapse

DISTORTIONS =
['none', 'low', 'medium', 'high']
@@image_styles =
{
  'simply_red'   => ['-alpha set', '-fill darkred', '-background white', '-size 200x50', 'xc:white'],
  'simply_green' => ['-alpha set', '-fill darkgreen', '-background white', '-size 200x50', 'xc:white'],
  'simply_blue'  => ['-alpha set', '-fill darkblue', '-background white', '-size 200x50', 'xc:white'],
  'red'          => ['-alpha set', '-fill \#A5A5A5', '-background \#800E19', '-size 245x60', 'xc:\#800E19'],
}

Class Method Summary collapse

Class Method Details

.distortion(key = 'low') ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/simple_captcha/image.rb', line 35

def distortion(key='low')
  key =
    key == 'random' ?
    DISTORTIONS[rand(DISTORTIONS.length)] :
    DISTORTIONS.include?(key) ? key : 'low'
  case key.to_s
    when 'none' then return [0, 100]
    when 'low' then return [0 + rand(2), 80 + rand(20)]
    when 'medium' then return [2 + rand(2), 50 + rand(20)]
    when 'high' then return [4 + rand(2), 30 + rand(20)]
  end
end

.image_params(key = 'simply_blue') ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_captcha/image.rb', line 17

def image_params(key = 'simply_blue')
  image_keys = @@image_styles.keys

  style = begin
    if key == 'random'
      image_keys[rand(image_keys.length)]
    else
      image_keys.include?(key) ? key : 'simply_blue'
    end
  end

  @@image_styles[style]
end

.image_params_from_color(color) ⇒ Object



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

def image_params_from_color(color)
  ["-alpha set -background none -fill \"#{color}\""]
end