Newbie here.
This is not a question but a report on a work-around for a problem I
detected with the gem validates_captcha.
My environment is
Windows, Vista, Rails
Rails 2.3.5
Ruby 1.8.6
gem 1.3.5
validates_captcha-0.9.6
The problem:
validates_captcha is generating a default gif with the word "captcha"
in
it rather than a captcha with the value of a a random string (the
captcha) in it.
The work-around:
In module .\lib\validates_captcha\image_generator\simple.rb there is the
following module
- - - - - - - -
def generate(captcha_code)
image_width = captcha_code.length * 20 + 10
cmd = []
cmd << "convert -size #{image_width}x40 xc:grey84 -background
grey84 -fill black "
captcha_code.split(//).each_with_index do |char, i|
cmd << " -pointsize #{rand(8) + 15} "
cmd << " -weight #{rand(2) == 0 ? ''4'' :
''8''}00 "
cmd << " -draw ''text #{5 + 20 * i},#{rand(10) +
20}
\"#{char}\"'' "
end
cmd << " -rotate #{rand(2) == 0 ? ''-'' :
''''}5 -fill grey40 "
captcha_code.size.times do
cmd << " -draw ''line #{rand(image_width)},0
#{rand(image_width)},60'' "
end
cmd << " gif:-"
image_magick_command = cmd.join
`#{image_magick_command}`
end
- - - - - - - -
The problem appears to be in the line
cmd << " gif:-"
replace this with
cmd << " gif:c:\tmp\SomeTempFile.gif"
and then read (binary) c:\tmp\SomeTempFile.gif and push that string out
instead of `#{image_magick_command}` pumping the output to stdout.
SomeTempFile.gif should probably not be a unique name since several
users might want to generate captchas at the same time. I keyed my name
off of the captcha code but there may be a better way to do this. If
anone has a good solution to this, I''d love to hear it.
Oh, do remember to delete the uniquely named file or your tmp directory
will fill up quickly.
It works for me. Your mileage may vary.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.