Make sure it will render image when ImageMagick stderr have warning messages. (fix #26)

This commit is contained in:
Jason Lee 2016-06-22 11:05:30 +08:00
parent 38b6ac8ae1
commit bb74854cea
5 changed files with 20 additions and 7 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,3 @@
module RuCaptcha
VERSION = '0.5.0'
VERSION = '0.5.1'
end

View File

@ -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