glebtv-simple_captcha 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c317ffb46efc02b32a774729631923802e597047
4
- data.tar.gz: 38ddb5ce01cbdbc4bb626dfe13c999543e04cff1
3
+ metadata.gz: 449ca80c41d5dedc86f12d03538f9645a9dd7e45
4
+ data.tar.gz: 1a903f97a8f9101aeb807985ba229a252cf9969d
5
5
  SHA512:
6
- metadata.gz: 4a3f9a98aed2cb7e3d8135d5516e7d7daec23285d85586cfe06ab3463c3d53046e304b0bef5fa1612db48be05d9c4b226ba47b5a8422904cf1112c243c1e74db
7
- data.tar.gz: f20894ec31d8450f4d6ce6fbd1bd2fc286981e8424bf49a79af2890c2ea3a9703e68b893232365d65e51bd89fb6e460bbbf0b5effe6b6a1e937d39b0619dd1b6
6
+ metadata.gz: bd15460ff8d8ae922861b09fd920cf3fc4d6f8b6dd62ff9a3043085aeb11fae2157ffe89436e6e8ccaff26a1e17193d2cceaa7440a3b37d19c176ea057d946ed
7
+ data.tar.gz: 25670d30d876c24d618c04513a1ee6955e4a4338e5c79a89dc7306783517c10e90e0f904b9f533b134a97c20e33ffd0172d159f8893c64cfe4b3ccd2df2a8c86
@@ -4,14 +4,10 @@ module SimpleCaptcha #:nodoc
4
4
 
5
5
  mattr_accessor :image_styles
6
6
  @@image_styles = {
7
- 'embosed_silver' => ['-fill darkblue', '-shade 20x60', '-background white'],
8
- 'simply_red' => ['-fill darkred', '-background white'],
9
- 'simply_green' => ['-fill darkgreen', '-background white'],
10
- 'simply_blue' => ['-fill darkblue', '-background white'],
11
- 'distorted_black' => ['-fill darkblue', '-edge 10', '-background white'],
12
- 'all_black' => ['-fill darkblue', '-edge 2', '-background white'],
13
- 'charcoal_grey' => ['-fill darkblue', '-charcoal 5', '-background white'],
14
- 'almost_invisible' => ['-fill red', '-solarize 50', '-background white']
7
+ 'simply_red' => ['-alpha set', '-fill darkred', '-background white', '-size 200x50', 'xc:white'],
8
+ 'simply_green' => ['-alpha set', '-fill darkgreen', '-background white', '-size 200x50', 'xc:white'],
9
+ 'simply_blue' => ['-alpha set', '-fill darkblue', '-background white', '-size 200x50', 'xc:white'],
10
+ 'red' => ['-alpha set', '-fill \#A5A5A5', '-background \#800E19', '-size 245x60', 'xc:\#800E19'],
15
11
  }
16
12
 
17
13
  DISTORTIONS = ['low', 'medium', 'high']
@@ -68,10 +64,10 @@ module SimpleCaptcha #:nodoc
68
64
  params = ImageHelpers.image_params(SimpleCaptcha.image_style).dup
69
65
  else
70
66
  params = ImageHelpers.image_params_from_color(SimpleCaptcha.image_color).dup
67
+ params << "-size #{SimpleCaptcha.image_size} xc:transparent"
71
68
  end
72
-
73
- params << "-size #{SimpleCaptcha.image_size} xc:transparent"
74
69
  params << "-gravity \"Center\""
70
+
75
71
  psz = SimpleCaptcha.pointsize
76
72
  if params.join(' ').index('-pointsize').nil?
77
73
  params << "-pointsize #{psz}"
@@ -80,24 +76,26 @@ module SimpleCaptcha #:nodoc
80
76
  dst = Tempfile.new(RUBY_VERSION < '1.9' ? 'simple_captcha.png' : ['simple_captcha', '.png'], SimpleCaptcha.tmp_path)
81
77
  dst.binmode
82
78
  text.split(//).each_with_index do |letter, index|
83
- i = -(1.5 * psz) + (index * 0.75 * psz) + rand(-3..3)
79
+ i = -(2 * psz) + (index * 0.7 * psz) + rand(-3..3)
84
80
  params << "-draw \"translate #{i},#{rand(-3..3)} skewX #{rand(-15..15)} gravity center text 0,0 '#{letter}'\" "
85
81
  end
86
82
 
87
83
  params << "-wave #{amplitude}x#{frequency}"
88
84
 
89
- (1..10).each do |i|
90
- params << "-draw \"polyline #{rand(160)},#{rand(61)} #{rand(160)},#{rand(62)}\""
85
+ unless params.join(' ').index('-size').nil?
86
+ size = params.join(' ').match '-size (\d+)x(\d+)'
87
+ (1..SimpleCaptcha.wave_count).each do |i|
88
+ params << "-draw \"polyline #{rand(size[1].to_i)},#{rand(size[2].to_i)} #{rand(size[1].to_i)},#{rand(size[2].to_i)}\""
89
+ end
91
90
  end
92
91
 
93
92
  params << "\"#{File.expand_path(dst.path)}\""
94
- # puts "convert " + params.join(' ')
93
+
95
94
  SimpleCaptcha::Utils::run("convert", params.join(' '))
96
95
 
97
96
  dst.close
98
97
 
99
98
  File.expand_path(dst.path)
100
- #dst
101
99
  end
102
100
  end
103
101
  end
@@ -46,7 +46,12 @@ module SimpleCaptcha
46
46
  options[:filename] ||= File.basename(path) unless options[:url_based_filename]
47
47
 
48
48
  status = options[:status] || 200
49
- headers = {"Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'", "Content-Type" => options[:type], 'Content-Transfer-Encoding' => 'binary', 'Cache-Control' => 'private'}
49
+ headers = {
50
+ "Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'",
51
+ # "Content-Type" => options[:type],
52
+ 'Content-Transfer-Encoding' => 'binary',
53
+ 'Cache-Control' => 'private'
54
+ }
50
55
  response_body = [File.open(path, "rb").read]
51
56
  File.delete(path)
52
57
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module SimpleCaptcha
4
- VERSION = "0.6.0".freeze
4
+ VERSION = "0.6.1".freeze
5
5
  end
@@ -65,6 +65,9 @@ module SimpleCaptcha
65
65
  mattr_accessor :pointsize
66
66
  @@pointsize = 30
67
67
 
68
+ mattr_accessor :wave_count
69
+ @@wave_count = 10
70
+
68
71
  def self.add_image_style(name, params = [])
69
72
  SimpleCaptcha::ImageHelpers.image_styles.update(name.to_s => params)
70
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glebtv-simple_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GlebTv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-23 00:00:00.000000000 Z
11
+ date: 2014-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport