From b46a4ad0b4e6741a37cd1aee96f70504f687ccd7 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 20 May 2016 17:19:27 +0800 Subject: [PATCH] Lighter Text color. Remove OCR test. --- Gemfile | 2 -- Gemfile.lock | 3 --- lib/rucaptcha.rb | 8 ------- lib/rucaptcha/captcha.rb | 9 +++++--- spec/controller_helpers_spec.rb | 1 + spec/ocr_spec.rb | 37 --------------------------------- spec/spec_helper.rb | 2 -- 7 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 spec/ocr_spec.rb diff --git a/Gemfile b/Gemfile index 563e95f..46a4f91 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,4 @@ source 'https://rubygems.org' gemspec -# For test OCR -gem 'rtesseract' gem 'mini_magick' diff --git a/Gemfile.lock b/Gemfile.lock index f5f7a04..daad2dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,8 +102,6 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) rspec-support (3.3.0) - rtesseract (1.3.1) - nokogiri sprockets (3.3.5) rack (> 1, < 3) sprockets-rails (2.3.3) @@ -123,7 +121,6 @@ DEPENDENCIES rails rake rspec (>= 3.3.0) - rtesseract rucaptcha! BUNDLED WITH diff --git a/lib/rucaptcha.rb b/lib/rucaptcha.rb index 8275aae..c139f84 100644 --- a/lib/rucaptcha.rb +++ b/lib/rucaptcha.rb @@ -26,14 +26,6 @@ module RuCaptcha def configure(&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 if config.cache_limit >= 1 RuCaptcha::Captcha.send(:include, RuCaptcha::Cache) diff --git a/lib/rucaptcha/captcha.rb b/lib/rucaptcha/captcha.rb index 88aa1c8..602c653 100644 --- a/lib/rucaptcha/captcha.rb +++ b/lib/rucaptcha/captcha.rb @@ -5,7 +5,10 @@ module RuCaptcha class << self def random_color 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 color_seed = rand(50).to_s(8) [color_seed, color_seed, color_seed] @@ -35,7 +38,7 @@ module RuCaptcha half_height = full_height / 2 text_top = 0 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 label = "=#{' ' * (chars.size - 1)}=" @@ -58,7 +61,7 @@ module RuCaptcha #{line_opts.join(' ')} \ -pointsize #{font_size} -weight 500 \ #{text_opts.join(' ')} \ - -wave #{rand(2) + 3}x#{rand(2) + 1} \ + -wave #{rand(2) + 1}x#{rand(2) + 1} \ -rotate #{rand(10) - 5} \ -gravity NorthWest -sketch 1x10+#{rand(2)} \ -fill none \ diff --git a/spec/controller_helpers_spec.rb b/spec/controller_helpers_spec.rb index f1fc08b..34a1e5a 100644 --- a/spec/controller_helpers_spec.rb +++ b/spec/controller_helpers_spec.rb @@ -41,6 +41,7 @@ describe RuCaptcha do simple.session[:_rucaptcha] = 'abcd' simple.params[:_rucaptcha] = 'Abcd' expect(simple.verify_rucaptcha?).to eq(true) + simple.session[:_rucaptcha] = 'abcd' simple.params[:_rucaptcha] = 'AbcD' expect(simple.verify_rucaptcha?).to eq(true) end diff --git a/spec/ocr_spec.rb b/spec/ocr_spec.rb deleted file mode 100644 index 30e9bc2..0000000 --- a/spec/ocr_spec.rb +++ /dev/null @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eebdc01..553994d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,6 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'rucaptcha' -require 'rtesseract' tmp_path = File.join(File.dirname(__FILE__), '../tmp') if !File.exists?(tmp_path) @@ -21,7 +20,6 @@ end RuCaptcha.configure do self.len = 2 - self.height = 33 self.font_size = 48 self.implode = 0.111 end