From bb74854cea8f5dd1363e0ca4425ce8f9818f0c1e Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 22 Jun 2016 11:05:30 +0800 Subject: [PATCH] Make sure it will render image when ImageMagick stderr have warning messages. (fix #26) --- CHANGELOG.md | 6 ++++++ Gemfile.lock | 5 +++-- lib/rucaptcha/captcha.rb | 12 ++++++++---- lib/rucaptcha/version.rb | 2 +- rucaptcha.gemspec | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8364a72..3cc1490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +0.5.1 +----- + +- Make sure it will render image when ImageMagick stderr have warning messages. (#26) + 0.5.0 +----- - Fix cache with Rails 5. diff --git a/Gemfile.lock b/Gemfile.lock index c86999a..705b67f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,8 @@ PATH remote: . specs: - rucaptcha (0.5.0) + rucaptcha (0.5.1) + railties (>= 3.2) GEM remote: https://rubygems.org/ @@ -131,4 +132,4 @@ DEPENDENCIES rucaptcha! BUNDLED WITH - 1.12.4 + 1.12.5 diff --git a/lib/rucaptcha/captcha.rb b/lib/rucaptcha/captcha.rb index 8952f65..18a646f 100644 --- a/lib/rucaptcha/captcha.rb +++ b/lib/rucaptcha/captcha.rb @@ -71,17 +71,21 @@ module RuCaptcha if Gem.win_platform? png_file_path = Rails.root.join('tmp', 'cache', "#{code}.png") command = "convert -size #{size} xc:White -gravity Center -weight 12 -pointsize 20 -annotate 0 \"#{code}\" -trim #{png_file_path}" - require 'open3' - _stdout_str, stderr_str = Open3.capture3(command) - raise "RuCaptcha: #{stderr_str.strip}" if stderr_str.present? + out, err, _st = Open3.capture3(command) + warn " RuCaptcha #{err.strip}" if err.present? png_file_path else command.strip! out, err, _st = Open3.capture3(command) - raise "RuCaptcha: #{err.strip}" if err.present? + warn " RuCaptcha #{err.strip}" if err.present? out end end + + def warn(msg) + msg = " RuCaptcha #{msg}" + Rails.logger.error(msg) + end end end end diff --git a/lib/rucaptcha/version.rb b/lib/rucaptcha/version.rb index ef06ee8..03f518d 100644 --- a/lib/rucaptcha/version.rb +++ b/lib/rucaptcha/version.rb @@ -1,3 +1,3 @@ module RuCaptcha - VERSION = '0.5.0' + VERSION = '0.5.1' end diff --git a/rucaptcha.gemspec b/rucaptcha.gemspec index 228fa28..0272f0f 100644 --- a/rucaptcha.gemspec +++ b/rucaptcha.gemspec @@ -12,4 +12,6 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/huacnlee/rucaptcha' s.require_paths = ['lib'] s.summary = 'This is a Captcha gem for Rails Application. It run ImageMagick command to draw Captcha image.' + + s.add_dependency 'railties', '>= 3.2' end