Module: SimpleCaptcha::ImageHelpers

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

Overview

:nodoc

Defined Under Namespace

Classes: Tempfile

Constant Summary collapse

DISTORTIONS =
['low', 'medium', 'high']
IMPLODES =
{ 'none' => 0, 'low' => 0.1, 'medium' => 0.2, 'high' => 0.3 }
DEFAULT_IMPLODE =
'medium'
@@image_styles =
{
  'embosed_silver'  => ['-fill darkblue', '-shade 20x60', '-background white'],
  'simply_red'      => ['-fill darkred', '-background white'],
  'simply_green'    => ['-fill darkgreen', '-background white'],
  'simply_blue'     => ['-fill darkblue', '-background white'],
  'distorted_black' => ['-fill darkblue', '-edge 10', '-background white'],
  'all_black'       => ['-fill darkblue', '-edge 2', '-background white'],
  'charcoal_grey'   => ['-fill darkblue', '-charcoal 5', '-background white'],
  'almost_invisible' => ['-fill red', '-solarize 50', '-background white']
}

Class Method Summary collapse

Class Method Details

.distortion(key = 'low') ⇒ Object


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

def distortion(key='low')
  key =
    key == 'random' ?
    DISTORTIONS[rand(DISTORTIONS.length)] :
    DISTORTIONS.include?(key) ? key : 'low'
  case key.to_s
    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


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/simple_captcha/image.rb', line 24

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

.implodeObject


50
51
52
# File 'lib/simple_captcha/image.rb', line 50

def implode
  IMPLODES[SimpleCaptcha.implode] || IMPLODES[DEFAULT_IMPLODE]
end