lib/simple_captcha/image.rb in glebtv-simple_captcha-0.6.0 vs lib/simple_captcha/image.rb in glebtv-simple_captcha-0.6.1

- old
+ new

@@ -2,18 +2,14 @@ module SimpleCaptcha #:nodoc module ImageHelpers #:nodoc mattr_accessor :image_styles @@image_styles = { - 'embosed_silver' => ['-fill darkblue', '-shade 20x60', '-background white'], - 'simply_red' => ['-fill darkred', '-background white'], - 'simply_green' => ['-fill darkgreen', '-background white'], - 'simply_blue' => ['-fill darkblue', '-background white'], - 'distorted_black' => ['-fill darkblue', '-edge 10', '-background white'], - 'all_black' => ['-fill darkblue', '-edge 2', '-background white'], - 'charcoal_grey' => ['-fill darkblue', '-charcoal 5', '-background white'], - 'almost_invisible' => ['-fill red', '-solarize 50', '-background white'] + 'simply_red' => ['-alpha set', '-fill darkred', '-background white', '-size 200x50', 'xc:white'], + 'simply_green' => ['-alpha set', '-fill darkgreen', '-background white', '-size 200x50', 'xc:white'], + 'simply_blue' => ['-alpha set', '-fill darkblue', '-background white', '-size 200x50', 'xc:white'], + 'red' => ['-alpha set', '-fill \#A5A5A5', '-background \#800E19', '-size 245x60', 'xc:\#800E19'], } DISTORTIONS = ['low', 'medium', 'high'] class << self @@ -66,38 +62,40 @@ text = Utils::simple_captcha_new_value(simple_captcha_key) if SimpleCaptcha.image_color.nil? params = ImageHelpers.image_params(SimpleCaptcha.image_style).dup else params = ImageHelpers.image_params_from_color(SimpleCaptcha.image_color).dup + params << "-size #{SimpleCaptcha.image_size} xc:transparent" end - - params << "-size #{SimpleCaptcha.image_size} xc:transparent" params << "-gravity \"Center\"" + psz = SimpleCaptcha.pointsize if params.join(' ').index('-pointsize').nil? params << "-pointsize #{psz}" end dst = Tempfile.new(RUBY_VERSION < '1.9' ? 'simple_captcha.png' : ['simple_captcha', '.png'], SimpleCaptcha.tmp_path) dst.binmode text.split(//).each_with_index do |letter, index| - i = -(1.5 * psz) + (index * 0.75 * psz) + rand(-3..3) + i = -(2 * psz) + (index * 0.7 * psz) + rand(-3..3) params << "-draw \"translate #{i},#{rand(-3..3)} skewX #{rand(-15..15)} gravity center text 0,0 '#{letter}'\" " end params << "-wave #{amplitude}x#{frequency}" - (1..10).each do |i| - params << "-draw \"polyline #{rand(160)},#{rand(61)} #{rand(160)},#{rand(62)}\"" + unless params.join(' ').index('-size').nil? + size = params.join(' ').match '-size (\d+)x(\d+)' + (1..SimpleCaptcha.wave_count).each do |i| + params << "-draw \"polyline #{rand(size[1].to_i)},#{rand(size[2].to_i)} #{rand(size[1].to_i)},#{rand(size[2].to_i)}\"" + end end params << "\"#{File.expand_path(dst.path)}\"" - # puts "convert " + params.join(' ') + SimpleCaptcha::Utils::run("convert", params.join(' ')) dst.close File.expand_path(dst.path) - #dst end end end