Forum: Ruby on Rails rmagick and captcha

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B192011964906cffb106241f99cb4c3f?d=identicon&s=25 Rodrigo Dominguez (rdominguez)
on 2006-03-09 21:51
(Received via mailing list)
Has anyone implemented a captcha with ruby on rails and rmagick?
I tried this example:
http://wiki.rubyonrails.com/rails/pages/HowtoSecur...
but I got an error:
undefined method `size' for #<NoisyImage:0x34d8070>

Thank you


--------------------------------------------------


Rodrigo Dominguez
 
Iplan Networks                Datos Personales
rdominguez@iplan.com.ar       rorra@rorra.com.ar
www.iplan.com.ar              www.rorra.com.ar
5031-6303                     15-5695-6027
8acba6d057b3f0c2c16cca95ad36881b?d=identicon&s=25 Bakki Kudva (bakki)
on 2006-03-09 22:25
(Received via mailing list)
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
B192011964906cffb106241f99cb4c3f?d=identicon&s=25 Rodrigo Dominguez (rdominguez)
on 2006-03-09 23:32
(Received via mailing list)
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 ;)

----------------------------
Rodrigo Dominguez
 
Iplan Networks                
rdominguez@iplan.com.ar      
www.iplan.com.ar           
5031-6303                     

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

-----Mensaje original-----
De: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] En nombre de Bakki Kudva
Enviado el: Jueves, 09 de Marzo de 2006 06:25 p.m.
Para: rails@lists.rubyonrails.org
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 Dominguez <rails@rorra.com.ar> wrote:
> Has anyone implemented a captcha with ruby on rails and rmagick?
> I tried this example:
>
http://wiki.rubyonrails.com/rails/pages/HowtoSecur...
>
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
B192011964906cffb106241f99cb4c3f?d=identicon&s=25 Rodrigo Dominguez (rdominguez)
on 2006-03-09 23:35
(Received via mailing list)
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 Dominguez
 
Iplan Networks                
rdominguez@iplan.com.ar      
www.iplan.com.ar           
5031-6303                     

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

-----Mensaje original-----
De: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] En nombre de Bakki Kudva
Enviado el: Jueves, 09 de Marzo de 2006 06:25 p.m.
Para: rails@lists.rubyonrails.org
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 Dominguez <rails@rorra.com.ar> wrote:
> Has anyone implemented a captcha with ruby on rails and rmagick?
> I tried this example:
>
http://wiki.rubyonrails.com/rails/pages/HowtoSecur...
>
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
8acba6d057b3f0c2c16cca95ad36881b?d=identicon&s=25 Bakki Kudva (bakki)
on 2006-03-10 04:44
(Received via mailing list)
On 3/9/06, Rodrigo Dominguez <rails@rorra.com.ar> 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
B192011964906cffb106241f99cb4c3f?d=identicon&s=25 Rodrigo Dominguez (rdominguez)
on 2006-03-10 14:23
(Received via mailing list)
That was the error, thank you for your time

----------------------------
Rodrigo Dominguez
 
Iplan Networks                
rdominguez@iplan.com.ar      
www.iplan.com.ar           
5031-6303                     

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

-----Mensaje original-----
De: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] En nombre de Bakki Kudva
Enviado el: Viernes, 10 de Marzo de 2006 12:44 a.m.
Para: rails@lists.rubyonrails.org
Asunto: Re: [Rails] rmagick and captcha

On 3/9/06, Rodrigo Dominguez <rails@rorra.com.ar> 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 Dominguez <rails@rorra.com.ar> wrote:
> > Has anyone implemented a captcha with ruby on rails and rmagick?
> > I tried this example:
> >
>
http://wiki.rubyonrails.com/rails/pages/HowtoSecur...
> >
> > Rails@lists.rubyonrails.org
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
8acba6d057b3f0c2c16cca95ad36881b?d=identicon&s=25 Bakki Kudva (bakki)
on 2006-03-10 20:16
(Received via mailing list)
You are welcome. Glad to help.
-bakki
This topic is locked and can not be replied to.