Using open3 and sent file, also using simplify as it only intent to use in development.
This commit is contained in:
parent
bd138df5b8
commit
05cb20fe9d
|
@ -4,7 +4,11 @@ module RuCaptcha
|
||||||
headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
|
headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
|
||||||
headers['Pragma'] = 'no-cache'
|
headers['Pragma'] = 'no-cache'
|
||||||
|
|
||||||
|
if Gem.win_platform?
|
||||||
|
send_file generate_rucaptcha, disposition: 'inline', type: 'image/png'
|
||||||
|
else
|
||||||
send_data generate_rucaptcha, disposition: 'inline', type: 'image/png'
|
send_data generate_rucaptcha, disposition: 'inline', type: 'image/png'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,6 +60,14 @@ module RuCaptcha
|
||||||
-implode #{RuCaptcha.config.implode} -trim label:- png:-
|
-implode #{RuCaptcha.config.implode} -trim label:- png:-
|
||||||
CODE
|
CODE
|
||||||
|
|
||||||
|
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 != nil && stderr_str.length > 0
|
||||||
|
png_file_path
|
||||||
|
else
|
||||||
command.strip!
|
command.strip!
|
||||||
pid, stdin, stdout, stderr = POSIX::Spawn.popen4(command)
|
pid, stdin, stdout, stderr = POSIX::Spawn.popen4(command)
|
||||||
Process.waitpid(pid)
|
Process.waitpid(pid)
|
||||||
|
@ -69,4 +77,5 @@ module RuCaptcha
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue