rucaptcha 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36a708da1441244cec7d341d61f6c9dd56b59841
4
- data.tar.gz: ce262c5cc8f5aa141ba48403d7cf57d072e75908
3
+ metadata.gz: 426e52c0e7d7b9691d077e57707d49893b8b8298
4
+ data.tar.gz: 1facb980237b56228e4f24758c63ac120b92895a
5
5
  SHA512:
6
- metadata.gz: ab54bed90febe81bc5d6abb3417167e85e4d4e7e520810222392ef9e029f6d1dd6f520a4b465ec3f9db82a44953b6d3499bf7f300e8b09dfeed0dc77208eb1c7
7
- data.tar.gz: 731405ff4ec6e7789f044fda7c003f087f8b1210ad968eeb66f1662b10f9086bf408d19c5b33652078d8ca49f5567758fbefd2e97950081a683c70467a5f42bc
6
+ metadata.gz: 0365c36e90ed6ec817b2154161cd01d014bf29ab57ef27f54f04b7a9dda0ed0676cb9e4f7d1c452d7fff7ba688a2a8907fb80c32ac9f6c175e3635e05ab3ec69
7
+ data.tar.gz: d29fde1ca29dc61a041dc54891b0badd73e52add5a7e484dc42b66adc3363b07f06e2026d7d9d851d1b0cd892ab51787d4c83a4160305405fccc7163345d65ff
@@ -1,3 +1,9 @@
1
+ 0.3.2
2
+ -----
3
+
4
+ - Make better render positions;
5
+ - Trim blank space.
6
+
1
7
  0.3.1
2
8
  -----
3
9
 
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 6.9+
24
+ - ImageMagick
25
25
 
26
26
  #### Ubuntu
27
27
 
@@ -37,9 +37,14 @@ brew install imagemagick ghostscript
37
37
 
38
38
  ## Example
39
39
 
40
- ![rucaptcha1](https://cloud.githubusercontent.com/assets/5518/10726119/a844dfce-7c0b-11e5-99c3-a818f3ef3dd2.png) ![rucaptcha2](https://cloud.githubusercontent.com/assets/5518/10747608/2f2f5f10-7c92-11e5-860b-914db5695a57.png) ![rucaptcha3](https://cloud.githubusercontent.com/assets/5518/10747609/2f5bbac4-7c92-11e5-8192-4aa5dfb025b7.png) ![rucaptcha4](https://cloud.githubusercontent.com/assets/5518/10747611/2f7c6a12-7c92-11e5-8730-de7295b36dd6.png) ![rucaptcha5](https://cloud.githubusercontent.com/assets/5518/10747610/2f7a9d86-7c92-11e5-911a-44596c9aeef5.png)
41
-
42
-
40
+ ![captcha8](https://cloud.githubusercontent.com/assets/5518/10965901/f8e17118-83ea-11e5-935d-a17fd6ab8307.png)
41
+ ![captcha7](https://cloud.githubusercontent.com/assets/5518/10965903/f8e34b5a-83ea-11e5-9f8e-e43fc78347a7.png)
42
+ ![captcha6](https://cloud.githubusercontent.com/assets/5518/10965902/f8e2f132-83ea-11e5-89f5-b75aedbcfb2f.png)
43
+ ![captcha5](https://cloud.githubusercontent.com/assets/5518/10965904/f920ec44-83ea-11e5-89d2-3312da0f2bc4.png)
44
+ ![captcha4](https://cloud.githubusercontent.com/assets/5518/10965905/f92264ac-83ea-11e5-96b0-2e81ee78d073.png)
45
+ ![captcha3](https://cloud.githubusercontent.com/assets/5518/10965906/f9279652-83ea-11e5-94fa-a9cd2df9beec.png)
46
+ ![captcha2](https://cloud.githubusercontent.com/assets/5518/10965909/f9623e24-83ea-11e5-8ad3-d4bf94edfe1b.png)
47
+ ![captcha1](https://cloud.githubusercontent.com/assets/5518/10965908/f95fedfe-83ea-11e5-990b-fdcd2d1a97aa.png)
43
48
 
44
49
  ## Usage
45
50
 
@@ -55,8 +60,8 @@ Create `config/initializers/rucaptcha.rb`
55
60
  RuCaptcha.configure do
56
61
  # Number of chars, default: 4
57
62
  self.len = 4
58
- # Image font size, default: 48
59
- self.font_size = 48
63
+ # Image font size, default: 45
64
+ self.font_size = 45
60
65
  # Cache generated images in file store, this is config files limit, default: 100
61
66
  # set 0 to disable file cache.
62
67
  self.cache_limit = 100
@@ -7,5 +7,4 @@ module RuCaptcha
7
7
  send_data generate_rucaptcha, disposition: 'inline', type: 'image/png'
8
8
  end
9
9
  end
10
-
11
10
  end
@@ -14,7 +14,7 @@ module RuCaptcha
14
14
  end
15
15
 
16
16
  def rand_line_top(text_top, font_size)
17
- text_top + rand(font_size - text_top * 2)
17
+ text_top + rand(font_size * 0.7).to_i
18
18
  end
19
19
 
20
20
  # Create Captcha image by code
@@ -23,19 +23,17 @@ module RuCaptcha
23
23
  all_left = 20
24
24
  font_size = RuCaptcha.config.font_size
25
25
  full_height = font_size
26
- full_width = (font_size * chars.size)
26
+ full_width = font_size * chars.size
27
27
  size = "#{full_width}x#{full_height}"
28
28
  half_width = full_width / 2
29
29
  full_height = full_height
30
30
  half_height = full_height / 2
31
- text_top = 10
31
+ text_top = 0
32
32
  text_left = 0 - (font_size * 0.28).to_i
33
33
  stroke_width = (font_size * 0.08).to_i + 1
34
- text_width = (full_width / chars.size) + text_left
34
+ text_width = font_size + text_left
35
35
  label = "=#{' ' * (chars.size - 1)}="
36
36
 
37
-
38
-
39
37
  text_opts = []
40
38
  line_opts = []
41
39
  chars.each_with_index do |char, i|
@@ -44,8 +42,9 @@ module RuCaptcha
44
42
  line_color = "rgba(#{rgb.join(',')}, 0.6)"
45
43
  text_opts << %(-fill '#{text_color}' -draw 'text #{(text_left + text_width) * i + all_left},#{text_top} "#{char}"')
46
44
  left_y = rand_line_top(text_top, font_size)
45
+ right_x = half_width + (half_width * 0.3).to_i
47
46
  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}')
47
+ line_opts << %(-draw 'stroke #{line_color} line #{rand(10)},#{left_y} #{right_x},#{right_y}')
49
48
  end
50
49
 
51
50
  command = <<-CODE
@@ -57,8 +56,8 @@ module RuCaptcha
57
56
  -wave #{rand(2) + 3}x#{rand(2) + 1} \
58
57
  -rotate #{rand(10) - 5} \
59
58
  -gravity NorthWest -sketch 1x10+#{rand(2)} \
60
- -fill white \
61
- -implode #{RuCaptcha.config.implode} label:- png:-
59
+ -fill none \
60
+ -implode #{RuCaptcha.config.implode} -trim label:- png:-
62
61
  CODE
63
62
 
64
63
  command.strip!
@@ -2,7 +2,7 @@ module RuCaptcha
2
2
  class Configuration
3
3
  # TODO: remove height, width in 0.3.0
4
4
  attr_accessor :height, :width
5
- # Image font size, default 48
5
+ # Image font size, default 45
6
6
  attr_accessor :font_size
7
7
  # Number of chars, default 4
8
8
  attr_accessor :len
@@ -16,7 +16,7 @@ module RuCaptcha
16
16
  def verify_rucaptcha?(resource = nil)
17
17
  rucaptcha_at = session[:_rucaptcha_at].to_i
18
18
  # Captcha chars in Session expire in 2 minutes
19
- if rucaptcha_at.blank? || (Time.now.to_i - rucaptcha_at) > 120
19
+ if (Time.now.to_i - rucaptcha_at) > 120
20
20
  return false
21
21
  end
22
22
 
@@ -1,3 +1,3 @@
1
1
  module RuCaptcha
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  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.3.1
4
+ version: 0.3.2
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-05 00:00:00.000000000 Z
11
+ date: 2015-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: posix-spawn
@@ -113,3 +113,4 @@ specification_version: 4
113
113
  summary: This is a Captcha gem for Rails Application. It run ImageMagick command to
114
114
  draw Captcha image.
115
115
  test_files: []
116
+ has_rdoc: