From 72d9e145dbbf789b88a9fbf12810d0ffe4fbcbb6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 1 Sep 2016 14:20:25 +0800 Subject: [PATCH] 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. --- CHANGELOG.md | 7 +++++++ Gemfile.lock | 2 +- lib/rucaptcha/captcha.rb | 29 +++++++++++++++++++++-------- lib/rucaptcha/version.rb | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cc1490..6bfc9f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ----- diff --git a/Gemfile.lock b/Gemfile.lock index 705b67f..ec66969 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - rucaptcha (0.5.1) + rucaptcha (1.0.0) railties (>= 3.2) GEM diff --git a/lib/rucaptcha/captcha.rb b/lib/rucaptcha/captcha.rb index 18a646f..1687f8b 100644 --- a/lib/rucaptcha/captcha.rb +++ b/lib/rucaptcha/captcha.rb @@ -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}"') diff --git a/lib/rucaptcha/version.rb b/lib/rucaptcha/version.rb index 03f518d..12a51a3 100644 --- a/lib/rucaptcha/version.rb +++ b/lib/rucaptcha/version.rb @@ -1,3 +1,3 @@ module RuCaptcha - VERSION = '0.5.1' + VERSION = '1.0.0' end