rucaptcha 0.2.5 → 0.3.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: 83dddcf03d3e8acd1121b05f1336d520dc5af592
4
- data.tar.gz: 68308146916e90db9ff32b4f02906988528812b2
3
+ metadata.gz: 36a708da1441244cec7d341d61f6c9dd56b59841
4
+ data.tar.gz: ce262c5cc8f5aa141ba48403d7cf57d072e75908
5
5
  SHA512:
6
- metadata.gz: b79383bab6530fb996518f8faa08e67fae2bb8c43de138a5e874ebe4866a5df7e901ea7a5e4475eb50b6d060d2e61470b18d3add84fbe336f0e9184762a1b2dc
7
- data.tar.gz: 7d43f1c0416454ebbc8bc19c012e90712d41acae249a77c59eaec6be1a02a4eff4c45e3f2940e22c035d8d5193351c7a11b18d2331c0b52bbc3ed87eb175a49f
6
+ metadata.gz: ab54bed90febe81bc5d6abb3417167e85e4d4e7e520810222392ef9e029f6d1dd6f520a4b465ec3f9db82a44953b6d3499bf7f300e8b09dfeed0dc77208eb1c7
7
+ data.tar.gz: 731405ff4ec6e7789f044fda7c003f087f8b1210ad968eeb66f1662b10f9086bf408d19c5b33652078d8ca49f5567758fbefd2e97950081a683c70467a5f42bc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ 0.3.1
2
+ -----
3
+
4
+ - More complex Image render: compact text, strong lines, +/-5 rotate...
5
+ - [DEPRECATION] config.width, config.height removed, use config.font_size.
6
+ - Fix the render position in difference font sizes.
7
+ - Fix input field type, and disable autocorrect, autocapitalize, and limit maxlength with char length;
8
+
1
9
  0.2.5
2
10
  -----
3
11
 
data/README.md CHANGED
@@ -21,7 +21,7 @@ Idea by: https://ruby-china.org/topics/20558#reply4
21
21
 
22
22
  ## Requirements
23
23
 
24
- - ImageMagick
24
+ - ImageMagick 6.9+
25
25
 
26
26
  #### Ubuntu
27
27
 
@@ -55,10 +55,8 @@ Create `config/initializers/rucaptcha.rb`
55
55
  RuCaptcha.configure do
56
56
  # Number of chars, default: 4
57
57
  self.len = 4
58
- # Image width, default: 180
59
- self.width = 180
60
- # Image height, default: 48
61
- self.height = 48
58
+ # Image font size, default: 48
59
+ self.font_size = 48
62
60
  # Cache generated images in file store, this is config files limit, default: 100
63
61
  # set 0 to disable file cache.
64
62
  self.cache_limit = 100
data/lib/rucaptcha.rb CHANGED
@@ -15,8 +15,7 @@ module RuCaptcha
15
15
  return @config if defined?(@config)
16
16
  @config = Configuration.new
17
17
  @config.len = 4
18
- @config.width = 150
19
- @config.height = 48
18
+ @config.font_size = 45
20
19
  @config.implode = 0.4
21
20
  @config.cache_limit = 100
22
21
  @config
@@ -25,6 +24,14 @@ module RuCaptcha
25
24
  def configure(&block)
26
25
  config.instance_exec(&block)
27
26
 
27
+ if config.width != nil
28
+ ActiveSupport::Deprecation.warn("RuCaptcha config.width will remove in 0.4.0")
29
+ end
30
+
31
+ if config.height != nil
32
+ ActiveSupport::Deprecation.warn("RuCaptcha config.height will remove in 0.4.0")
33
+ end
34
+
28
35
  # enable cache if cache_limit less than 1
29
36
  if config.cache_limit >= 1
30
37
  RuCaptcha::Captcha.send(:include, RuCaptcha::Cache)
@@ -4,9 +4,7 @@ module RuCaptcha
4
4
  class Captcha
5
5
  class << self
6
6
  def rand_color
7
- rgb = [rand(100).to_s(8), rand(100).to_s(8), rand(100).to_s(8)]
8
-
9
- "rgba(#{rgb.join(',')},1)"
7
+ [rand(100).to_s(8), rand(100).to_s(8), rand(100).to_s(8)]
10
8
  end
11
9
 
12
10
  def random_chars
@@ -15,31 +13,51 @@ module RuCaptcha
15
13
  chars
16
14
  end
17
15
 
16
+ def rand_line_top(text_top, font_size)
17
+ text_top + rand(font_size - text_top * 2)
18
+ end
19
+
18
20
  # Create Captcha image by code
19
21
  def create(code)
20
- size = "#{RuCaptcha.config.width}x#{RuCaptcha.config.height}"
21
- font_size = (RuCaptcha.config.height * 0.8).to_i
22
- half_width = RuCaptcha.config.width / 2
23
- half_height = RuCaptcha.config.height / 2
24
- line_color = rand_color
25
22
  chars = code.split('')
26
- text_opts = []
27
- text_top = (RuCaptcha.config.height - font_size) / 2
28
- text_padding = 5
29
- text_width = (RuCaptcha.config.width / chars.size) - text_padding * 2
30
- text_left = 5
23
+ all_left = 20
24
+ font_size = RuCaptcha.config.font_size
25
+ full_height = font_size
26
+ full_width = (font_size * chars.size)
27
+ size = "#{full_width}x#{full_height}"
28
+ half_width = full_width / 2
29
+ full_height = full_height
30
+ half_height = full_height / 2
31
+ text_top = 10
32
+ text_left = 0 - (font_size * 0.28).to_i
33
+ stroke_width = (font_size * 0.08).to_i + 1
34
+ text_width = (full_width / chars.size) + text_left
35
+ label = "=#{' ' * (chars.size - 1)}="
36
+
37
+
31
38
 
39
+ text_opts = []
40
+ line_opts = []
32
41
  chars.each_with_index do |char, i|
33
- text_opts << %(-fill '#{rand_color}' -draw 'text #{(text_left + text_width) * i + text_left},#{text_top} "#{char}"')
42
+ rgb = rand_color
43
+ text_color = "rgba(#{rgb.join(',')}, 1)"
44
+ line_color = "rgba(#{rgb.join(',')}, 0.6)"
45
+ text_opts << %(-fill '#{text_color}' -draw 'text #{(text_left + text_width) * i + all_left},#{text_top} "#{char}"')
46
+ left_y = rand_line_top(text_top, font_size)
47
+ right_y = rand_line_top(text_top, font_size)
48
+ line_opts << %(-draw 'stroke #{line_color} line #{rand(10)},#{left_y} #{half_width + rand(half_width / 2)},#{right_y}')
34
49
  end
35
50
 
36
51
  command = <<-CODE
37
- convert -size #{size} #{text_opts.join(' ')} \
38
- -draw 'stroke #{line_color} line #{rand(10)},#{rand(20)} #{half_width + rand(half_width)},#{rand(half_height)}' \
39
- -draw 'stroke #{line_color} line #{rand(10)},#{rand(25)} #{half_width + rand(half_width)},#{half_height + rand(half_height)}' \
40
- -draw 'stroke #{line_color} line #{rand(10)},#{rand(30)} #{half_width + rand(half_width)},#{half_height + rand(half_height)}' \
41
- -wave #{rand(2) + 2}x#{rand(2) + 1} \
42
- -gravity NorthWest -sketch 1x10+#{rand(1)} -pointsize #{font_size} -weight 700 \
52
+ convert -size #{size} \
53
+ -strokewidth #{stroke_width} \
54
+ #{line_opts.join(' ')} \
55
+ -pointsize #{font_size} -weight 500 \
56
+ #{text_opts.join(' ')} \
57
+ -wave #{rand(2) + 3}x#{rand(2) + 1} \
58
+ -rotate #{rand(10) - 5} \
59
+ -gravity NorthWest -sketch 1x10+#{rand(2)} \
60
+ -fill white \
43
61
  -implode #{RuCaptcha.config.implode} label:- png:-
44
62
  CODE
45
63
 
@@ -1,9 +1,9 @@
1
1
  module RuCaptcha
2
2
  class Configuration
3
- # Image width, default 150
4
- attr_accessor :width
5
- # Image height, default 48
6
- attr_accessor :height
3
+ # TODO: remove height, width in 0.3.0
4
+ attr_accessor :height, :width
5
+ # Image font size, default 48
6
+ attr_accessor :font_size
7
7
  # Number of chars, default 4
8
8
  attr_accessor :len
9
9
  # implode, default 0.4
@@ -1,3 +1,3 @@
1
1
  module RuCaptcha
2
- VERSION = '0.2.5'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -2,7 +2,11 @@ module RuCaptcha
2
2
  module ViewHelpers
3
3
  def rucaptcha_input_tag(opts = {})
4
4
  opts[:name] = '_rucaptcha'
5
- opts[:type] = 'email'
5
+ opts[:type] = 'text'
6
+ opts[:autocorrect] = 'off'
7
+ opts[:autocapitalize] = 'off'
8
+ opts[:pattern] = '[0-9a-z]*'
9
+ opts[:maxlength] = RuCaptcha.config.len
6
10
  opts[:autocomplete] = 'off'
7
11
  tag(:input, opts)
8
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-02 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: posix-spawn