Rmagick and captcha


#1

Has anyone implemented a captcha with ruby on rails and rmagick?
I tried this example:
http://wiki.rubyonrails.com/rails/pages/HowtoSecureFormsWithNoisyImages
but I got an error:
undefined method `size’ for #NoisyImage:0x34d8070

Thank you


Rodrigo D.

Iplan Networks Datos Personales
removed_email_address@domain.invalid removed_email_address@domain.invalid
www.iplan.com.ar www.rorra.com.ar
5031-6303 15-5695-6027


#2

Hi Rodrigo,

I am the author of the article in your msg.
I am not sure how you are getting that error. The NoisyImage class has
no other methods defined other than the initialize code. Which gets
called when you do session[:noisy_image] = NoisyImage.new(6).

The image size is hard coded in the NoisyImage class and you can
change it to whatever size you want on this line, in the NoisyImage
class…

canvas.new_image(32*len, 50, Magick::TextureFill.new(granite))

If you’d like you can create some vars named height and width and use
them instead.
width = 32 (or whatever - this is a per character width which gets
multiplied by the length of the code string, which you can also change
in you call to NoisyImage.new(length) I have it hard coded at six
chars.
height = 50
canvas.new_image(width*len, height, Magick::TextureFill.new(granite))

Hope it solves your problem.

bakki


#3

Hi bakki

I just copy and pastle your code and it’s working now, thank you, you
did a great job, very easy to implement :wink:


Rodrigo D.

Iplan Networks
removed_email_address@domain.invalid
www.iplan.com.ar
5031-6303

Datos Personales
removed_email_address@domain.invalid
www.rorra.com.ar
15-5695-6027

-----Mensaje original-----
De: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] En nombre de Bakki K.
Enviado el: Jueves, 09 de Marzo de 2006 06:25 p.m.
Para: removed_email_address@domain.invalid
Asunto: Re: [Rails] rmagick and captcha

Hi Rodrigo,

I am the author of the article in your msg.
I am not sure how you are getting that error. The NoisyImage class has
no other methods defined other than the initialize code. Which gets
called when you do session[:noisy_image] = NoisyImage.new(6).

The image size is hard coded in the NoisyImage class and you can
change it to whatever size you want on this line, in the NoisyImage
class…

canvas.new_image(32*len, 50, Magick::TextureFill.new(granite))

If you’d like you can create some vars named height and width and use
them instead.
width = 32 (or whatever - this is a per character width which gets
multiplied by the length of the code string, which you can also change
in you call to NoisyImage.new(length) I have it hard coded at six
chars.
height = 50
canvas.new_image(width*len, height, Magick::TextureFill.new(granite))

Hope it solves your problem.

bakki

On 3/9/06, Rodrigo D. removed_email_address@domain.invalid wrote:

Has anyone implemented a captcha with ruby on rails and rmagick?
I tried this example:

http://wiki.rubyonrails.com/rails/pages/HowtoSecureFormsWithNoisyImages

removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#4

There is something that I just can’t understand…

In the article, you wrote this:

def protect
unless session[:noisy_image]
session[:noisy_image] = NoisyImage.new(6)
session[:code] = session[:noisy_image].code
end
end

def code_image
image = session[:noisy_image].code_image
send_data image, :type => ‘image/jpeg’, :disposition => ‘inline’
end

but if I write

def code_image
image = NoisyImage.new(6)
send_data image, :type => ‘image/jpeg’, :disposition => ‘inline’
end

the image is not displaying anymore, and I don’t know why… (actually,
that was the error that I was getting before)


Rodrigo D.

Iplan Networks
removed_email_address@domain.invalid
www.iplan.com.ar
5031-6303

Datos Personales
removed_email_address@domain.invalid
www.rorra.com.ar
15-5695-6027

-----Mensaje original-----
De: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] En nombre de Bakki K.
Enviado el: Jueves, 09 de Marzo de 2006 06:25 p.m.
Para: removed_email_address@domain.invalid
Asunto: Re: [Rails] rmagick and captcha

Hi Rodrigo,

I am the author of the article in your msg.
I am not sure how you are getting that error. The NoisyImage class has
no other methods defined other than the initialize code. Which gets
called when you do session[:noisy_image] = NoisyImage.new(6).

The image size is hard coded in the NoisyImage class and you can
change it to whatever size you want on this line, in the NoisyImage
class…

canvas.new_image(32*len, 50, Magick::TextureFill.new(granite))

If you’d like you can create some vars named height and width and use
them instead.
width = 32 (or whatever - this is a per character width which gets
multiplied by the length of the code string, which you can also change
in you call to NoisyImage.new(length) I have it hard coded at six
chars.
height = 50
canvas.new_image(width*len, height, Magick::TextureFill.new(granite))

Hope it solves your problem.

bakki

On 3/9/06, Rodrigo D. removed_email_address@domain.invalid wrote:

Has anyone implemented a captcha with ruby on rails and rmagick?
I tried this example:

http://wiki.rubyonrails.com/rails/pages/HowtoSecureFormsWithNoisyImages

removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#5

That was the error, thank you for your time


Rodrigo D.

Iplan Networks
removed_email_address@domain.invalid
www.iplan.com.ar
5031-6303

Datos Personales
removed_email_address@domain.invalid
www.rorra.com.ar
15-5695-6027

-----Mensaje original-----
De: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] En nombre de Bakki K.
Enviado el: Viernes, 10 de Marzo de 2006 12:44 a.m.
Para: removed_email_address@domain.invalid
Asunto: Re: [Rails] rmagick and captcha

On 3/9/06, Rodrigo D. removed_email_address@domain.invalid wrote:

end

Here’s the problem. WHen you do …
image = NoisyImage.new(6)
you are creating a NoisyImage object. The actual image binary is
contained in the @code_image instance variable. If you see the code
there are two accessor methods. First is :code (string) and the other
:code_image (binary image data). So you will have to send it in your
example as…
send_data image.code_image, :type => ‘image/jpeg’, :disposition =>
‘inline’

In my code I had done that earlier in the line…
image = session[:noisy_image].code_image
since I was saving the noisy_image object in the session.

Hope that clarifies.

bakki

the image is not displaying anymore, and I don’t know why…
(actually,
Datos Personales

Hope it solves your problem.

bakki

On 3/9/06, Rodrigo D. removed_email_address@domain.invalid wrote:

Has anyone implemented a captcha with ruby on rails and rmagick?
I tried this example:

http://wiki.rubyonrails.com/rails/pages/HowtoSecureFormsWithNoisyImages

removed_email_address@domain.invalid
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#6

On 3/9/06, Rodrigo D. removed_email_address@domain.invalid wrote:

end

Here’s the problem. WHen you do …
image = NoisyImage.new(6)
you are creating a NoisyImage object. The actual image binary is
contained in the @code_image instance variable. If you see the code
there are two accessor methods. First is :code (string) and the other
:code_image (binary image data). So you will have to send it in your
example as…
send_data image.code_image, :type => ‘image/jpeg’, :disposition =>
‘inline’

In my code I had done that earlier in the line…
image = session[:noisy_image].code_image
since I was saving the noisy_image object in the session.

Hope that clarifies.

bakki


#7

You are welcome. Glad to help.
-bakki