Lighter Text color.

Remove OCR test.
This commit is contained in:
Jason Lee 2016-05-20 17:19:27 +08:00
parent ca90a9221b
commit b46a4ad0b4
7 changed files with 7 additions and 55 deletions

View File

@ -1,6 +1,4 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gemspec gemspec
# For test OCR
gem 'rtesseract'
gem 'mini_magick' gem 'mini_magick'

View File

@ -102,8 +102,6 @@ GEM
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0) rspec-support (~> 3.3.0)
rspec-support (3.3.0) rspec-support (3.3.0)
rtesseract (1.3.1)
nokogiri
sprockets (3.3.5) sprockets (3.3.5)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-rails (2.3.3) sprockets-rails (2.3.3)
@ -123,7 +121,6 @@ DEPENDENCIES
rails rails
rake rake
rspec (>= 3.3.0) rspec (>= 3.3.0)
rtesseract
rucaptcha! rucaptcha!
BUNDLED WITH BUNDLED WITH

View File

@ -26,14 +26,6 @@ module RuCaptcha
def configure(&block) def configure(&block)
config.instance_exec(&block) config.instance_exec(&block)
if config.width != nil
ActiveSupport::Deprecation.warn("RuCaptcha config.width will remove in 0.4.0")
end
if config.height != nil
ActiveSupport::Deprecation.warn("RuCaptcha config.height will remove in 0.4.0")
end
# enable cache if cache_limit less than 1 # enable cache if cache_limit less than 1
if config.cache_limit >= 1 if config.cache_limit >= 1
RuCaptcha::Captcha.send(:include, RuCaptcha::Cache) RuCaptcha::Captcha.send(:include, RuCaptcha::Cache)

View File

@ -5,7 +5,10 @@ module RuCaptcha
class << self class << self
def random_color def random_color
if RuCaptcha.config.style == :colorful if RuCaptcha.config.style == :colorful
[rand(100).to_s(8), rand(100).to_s(8), rand(100).to_s(8)] color_seed = (rand(150) + 40).to_s(8)
color = [0.to_s(8), 0.to_s(8), 0.to_s(8)]
color[rand(3)] = color_seed
color
else else
color_seed = rand(50).to_s(8) color_seed = rand(50).to_s(8)
[color_seed, color_seed, color_seed] [color_seed, color_seed, color_seed]
@ -35,7 +38,7 @@ module RuCaptcha
half_height = full_height / 2 half_height = full_height / 2
text_top = 0 text_top = 0
text_left = 0 - (font_size * 0.28).to_i text_left = 0 - (font_size * 0.28).to_i
stroke_width = (font_size * 0.08).to_i + 1 stroke_width = (font_size * 0.05).to_i + 1
text_width = font_size + text_left text_width = font_size + text_left
label = "=#{' ' * (chars.size - 1)}=" label = "=#{' ' * (chars.size - 1)}="
@ -58,7 +61,7 @@ module RuCaptcha
#{line_opts.join(' ')} \ #{line_opts.join(' ')} \
-pointsize #{font_size} -weight 500 \ -pointsize #{font_size} -weight 500 \
#{text_opts.join(' ')} \ #{text_opts.join(' ')} \
-wave #{rand(2) + 3}x#{rand(2) + 1} \ -wave #{rand(2) + 1}x#{rand(2) + 1} \
-rotate #{rand(10) - 5} \ -rotate #{rand(10) - 5} \
-gravity NorthWest -sketch 1x10+#{rand(2)} \ -gravity NorthWest -sketch 1x10+#{rand(2)} \
-fill none \ -fill none \

View File

@ -41,6 +41,7 @@ describe RuCaptcha do
simple.session[:_rucaptcha] = 'abcd' simple.session[:_rucaptcha] = 'abcd'
simple.params[:_rucaptcha] = 'Abcd' simple.params[:_rucaptcha] = 'Abcd'
expect(simple.verify_rucaptcha?).to eq(true) expect(simple.verify_rucaptcha?).to eq(true)
simple.session[:_rucaptcha] = 'abcd'
simple.params[:_rucaptcha] = 'AbcD' simple.params[:_rucaptcha] = 'AbcD'
expect(simple.verify_rucaptcha?).to eq(true) expect(simple.verify_rucaptcha?).to eq(true)
end end

View File

@ -1,37 +0,0 @@
require 'spec_helper'
require 'fileutils'
require 'tmpdir'
describe 'OCR' do
before do
@tmp_dir = Dir.mktmpdir
@samples = []
10.times do
@samples << SecureRandom.hex(2)
end
@filenames = []
@samples.each do |chars|
fname = File.join(@tmp_dir, "#{chars}.png")
img = RuCaptcha::Captcha.create(chars)
File.open(fname, 'w+') do |f|
f.puts img
end
@filenames << fname
end
end
after do
FileUtils.rm_f(@tmp_dir)
end
it 'should not read by OCR lib' do
results = []
@samples.each do |chars|
str = RTesseract.new(File.join(@tmp_dir, "#{chars}.png"), processor: 'mini_magick').to_s
results << "- Chars: #{chars}, OCR read #{str.strip}"
expect(chars).not_to eq(str)
end
puts %(\n------------------------\nOCR all results: \n#{results.join("\n")})
end
end

View File

@ -4,7 +4,6 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rucaptcha' require 'rucaptcha'
require 'rtesseract'
tmp_path = File.join(File.dirname(__FILE__), '../tmp') tmp_path = File.join(File.dirname(__FILE__), '../tmp')
if !File.exists?(tmp_path) if !File.exists?(tmp_path)
@ -21,7 +20,6 @@ end
RuCaptcha.configure do RuCaptcha.configure do
self.len = 2 self.len = 2
self.height = 33
self.font_size = 48 self.font_size = 48
self.implode = 0.111 self.implode = 0.111
end end