parent
ca90a9221b
commit
b46a4ad0b4
2
Gemfile
2
Gemfile
|
@ -1,6 +1,4 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gemspec
|
||||
# For test OCR
|
||||
gem 'rtesseract'
|
||||
gem 'mini_magick'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue