Version 1.0.0

- Adjust to avoid lighter colors.
- Avoid continuous chars have same color.
- Use same color for each chars in :black_white mode.
This commit is contained in:
Jason Lee 2016-09-01 14:20:25 +08:00
parent ed265d0d2f
commit 72d9e145db
4 changed files with 30 additions and 10 deletions

View File

@ -1,3 +1,10 @@
1.0.0
-----
- Adjust to avoid lighter colors.
- Avoid continuous chars have same color.
- Use same color for each chars in :black_white mode.
0.5.1
-----

View File

@ -1,7 +1,7 @@
PATH
remote: .
specs:
rucaptcha (0.5.1)
rucaptcha (1.0.0)
railties (>= 3.2)
GEM

View File

@ -5,19 +5,17 @@ module RuCaptcha
class << self
def random_color
if RuCaptcha.config.style == :colorful
color = [random_color_seed, random_color_seed, random_color_seed]
color[rand(3)] = 0.to_s(8)
color1 = rand(56) + 15
color2 = rand(10) + 140
color = [color1, color2, rand(15)]
color.shuffle!
color
else
color_seed = rand(50).to_s(8)
color_seed = rand(40) + 10
[color_seed, color_seed, color_seed]
end
end
def random_color_seed
(rand(150) + 10).to_s(8)
end
def random_chars
chars = SecureRandom.hex(RuCaptcha.config.len / 2).downcase
chars.gsub!(/[0ol1]/i, (rand(8) + 2).to_s)
@ -44,8 +42,23 @@ module RuCaptcha
text_opts = []
line_opts = []
rgbs = []
chars.count.times do |i|
color = random_color
if i > 0
preview_color = rgbs[i - 1]
# Avoid color same as preview color
if color.index(color.min) == preview_color.index(preview_color.min) &&
color.index(color.max) == preview_color.index(preview_color.max)
# adjust RGB order
color = [color[1], color[2], color[0]]
end
end
rgbs << color
end
chars.each_with_index do |char, i|
rgb = random_color
rgb = RuCaptcha.config.style == :colorful ? rgbs[i] : rgbs[0]
text_color = "rgba(#{rgb.join(',')}, 1)"
line_color = "rgba(#{rgb.join(',')}, 0.6)"
text_opts << %(-fill '#{text_color}' -draw 'text #{(text_left + text_width) * i + all_left},#{text_top} "#{char}"')

View File

@ -1,3 +1,3 @@
module RuCaptcha
VERSION = '0.5.1'
VERSION = '1.0.0'
end