Nitobi
About Nitobi
Services
Products
Home -> Blogs -> Alexei@Nitobi

Alexei@Nitobi

Ruby Captcha Alternative

June 18th, 2007

Having trouble with RMagic in Ruby on Rails? You can always do what I ended up doing today, and using the command line interface to ImageMagick instead of dealing with all the headaches I was having.

First, download ImageMagick. Compile it or get the binaries if on Win32.

Figure out your command line for convert to create an image, set the correct blurring and warbling filters. Eg:

convert -size 142×42 xc:white -font arial -pointsize 30 -tile pattern:checkerboard -annotate +10+30 MYSTRING -blur 0x1 -wave 1×3 -draw “line 20,50 90,10” captcha.jpg

Then, create a helper method to come up with a string and use system method to execute the command line and dump the file in the correct spot.

system(’convert -size 142×42 xc:white -font arial -pointsize 30 -tile pattern:checkerboard -annotate +10+30 ‘ + mystring + ‘ -blur 0×1 -wave 1×4 -draw “line ‘ + String((rand*142).round) + ‘,50 ‘ + String((rand*142).round) + ‘,0″ -draw “line ‘ + String((rand*142).round) + ‘,50 ‘ + String((rand*142).round) + ‘,0″ public/images/captcha/’ + filename + ‘.gif’)

resultstring = filename + “.gif”

| Del.icio.us

This entry was posted on Monday, June 18th, 2007 at 7:59 pm and is filed under User Interface, web development, resources, rubyonrails. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply


Search Posts

Pages

Archives

Categories

LinkedIn Profile

  • My Profile

www.flickr.com


All contents are (c) Copyright 2024, Nitobi Software Inc. All rights Reserved
Alexei@Nitobi Entries (RSS) and Comments (RSS).