Feature option to change color theme

* Add `config.style` option, to allow use change render style.
This commit is contained in:
Jason Lee committed 2016-04-06 15:50:30 +08:00
1 parent d5a0ecc6ac
commit 0a7fa3782b
8 files changed
+38 -5

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ module RuCaptcha
@config.implode = 0.4
@config.cache_limit = 100
@config.expires_in = 2.minutes
@config.style = :colorful
@config
end
+8 -3
View File
@@ -3,8 +3,13 @@ require 'posix-spawn'
module RuCaptcha
class Captcha
class << self
def rand_color
[rand(100).to_s(8), rand(100).to_s(8), rand(100).to_s(8)]
def random_color
if RuCaptcha.config.style == :colorful
[rand(100).to_s(8), rand(100).to_s(8), rand(100).to_s(8)]
else
color_seed = rand(50).to_s(8)
[color_seed, color_seed, color_seed]
end
end
def random_chars
@@ -37,7 +42,7 @@ module RuCaptcha
text_opts = []
line_opts = []
chars.each_with_index do |char, i|
rgb = rand_color
rgb = random_color
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}"')
+2
View File
@@ -11,6 +11,8 @@ module RuCaptcha
# Number of Captcha codes limit
# set 0 to disable limit and file cache, default: 100
attr_accessor :cache_limit
# Color style, default: :colorful, allows: [:colorful, :black_white]
attr_accessor :style
# session[:_rucaptcha] expire time, default 2 minutes
attr_accessor :expires_in
end
+1 -1
View File
@@ -1,3 +1,3 @@
module RuCaptcha
VERSION = '0.3.3'
VERSION = '0.4.0'
end