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 0.5.1
----- -----

View File

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

View File

@ -5,19 +5,17 @@ module RuCaptcha
class << self class << self
def random_color def random_color
if RuCaptcha.config.style == :colorful if RuCaptcha.config.style == :colorful
color = [random_color_seed, random_color_seed, random_color_seed] color1 = rand(56) + 15
color[rand(3)] = 0.to_s(8) color2 = rand(10) + 140
color = [color1, color2, rand(15)]
color.shuffle!
color color
else else
color_seed = rand(50).to_s(8) color_seed = rand(40) + 10
[color_seed, color_seed, color_seed] [color_seed, color_seed, color_seed]
end end
end end
def random_color_seed
(rand(150) + 10).to_s(8)
end
def random_chars def random_chars
chars = SecureRandom.hex(RuCaptcha.config.len / 2).downcase chars = SecureRandom.hex(RuCaptcha.config.len / 2).downcase
chars.gsub!(/[0ol1]/i, (rand(8) + 2).to_s) chars.gsub!(/[0ol1]/i, (rand(8) + 2).to_s)
@ -44,8 +42,23 @@ module RuCaptcha
text_opts = [] text_opts = []
line_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| 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)" text_color = "rgba(#{rgb.join(',')}, 1)"
line_color = "rgba(#{rgb.join(',')}, 0.6)" line_color = "rgba(#{rgb.join(',')}, 0.6)"
text_opts << %(-fill '#{text_color}' -draw 'text #{(text_left + text_width) * i + all_left},#{text_top} "#{char}"') 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 module RuCaptcha
VERSION = '0.5.1' VERSION = '1.0.0'
end end