anyone have a working captcha perl script for windows ?

J

Jack

Hi there, I have installed every CPAN Captcha image verification known
and cant get any of them to do a simple task - output to a directory a
set of Captcha images with codes and the code file..you would think
its simple, I tried GD:SecurityImage and this does nothing:

use GD::SecurityImage;

# Create a normal image
my $image = GD::SecurityImage->new(width => 80,
height => 30,
lines => 10,
gd_font => 'giant');
$image->random($your_random_str);
$image->create(normal => 'rect');
my($image_data, $mime_type, $random_number) = $image->out;


It runs but you have no way of knowing "where" the images were
placed. can anyone reply with a true to life working SIMPLE script
that just dumps the images and code file ??????
thank you,

Jack
 
L

lihao0129

Hi there, I have installed every CPAN Captcha image verification known
and cant get any of them to do a simple task - output to a directory a
set of Captcha images with codes and the code file..you would think
its simple, I tried GD:SecurityImage and this does nothing:

use GD::SecurityImage;

# Create a normal image
my $image = GD::SecurityImage->new(width => 80,
height => 30,
lines => 10,
gd_font => 'giant');
$image->random($your_random_str);
$image->create(normal => 'rect');
my($image_data, $mime_type, $random_number) = $image->out;

It runs but you have no way of knowing "where" the images were
placed. can anyone reply with a true to life working SIMPLE script
that just dumps the images and code file ??????

I suppose you were in a web-context, so you need to print out the
result to STDOUT. you need also send out content-type header before
sending your image data.. what I did with HTML::Mason:

my($image_data, $mime_type) = $image->out;
binmode STDOUT;
$m->clear_buffer();
$r->content_type("image/$mime_type") ;
$m->print($image_data);
$m->flush_buffer();
$m->abort();

If you were using plain-CGI, and your script filename is captcha.cgi,
then you probably can do things like:[sorry I have no experience with
plain CGI]

{
local $|++;
my($image_data, $mime_type) = $image->out;
binmode STDOUT;
print "Content-type=image/$mime_type";
print $image_data;
close STDOUT;
}

or something like that to print out image data to the web with a
proper content-type(make sure no other data are outputted before
sending content-type header), and then you can fetch it from the other
side with:
<img src="/path/to/captcha.cgi?R=..." alt="" />

For me, the random number is generated from outside captcha.cgi, and
passed in with an encrypted query string(i.e. R=#### as in the above
sample). you can then decrypt it at the beginning of your Perl script
captcha.cgi.. If you like this approach, you need also check out CPAN
for some Crypt:: modules(I am using Crypt::RC4 for this).

BTW. with GD::ImageSecurity, you dont need any temporary file to save
the images....

Good luck,
lihao
 
J

Jack

Hi there, I have installed every CPAN Captcha image verification known
and cant get any of them to do a simple task - output to a directory a
set of Captcha images with codes and the code file..you would think
its simple, I tried GD:SecurityImage and this does nothing:
 use GD::SecurityImage;
   # Create a normal image
   my $image = GD::SecurityImage->new(width   => 80,
                                      height  => 30,
                                      lines   => 10,
                                      gd_font => 'giant');
      $image->random($your_random_str);
      $image->create(normal => 'rect');
   my($image_data, $mime_type, $random_number) = $image->out;
It runs but you have no way of knowing "where" the images were
placed.  can anyone reply with a true to life working SIMPLE script
that just dumps the images and code file ??????

I suppose you were in a web-context, so you need to print out the
result to STDOUT. you need also send out content-type header before
sending your image data.. what I did with HTML::Mason:

    my($image_data, $mime_type) = $image->out;
    binmode STDOUT;
    $m->clear_buffer();
    $r->content_type("image/$mime_type") ;
    $m->print($image_data);
    $m->flush_buffer();
    $m->abort();

If you were using plain-CGI, and your script filename is captcha.cgi,
then you probably can do things like:[sorry I have no experience with
plain CGI]

    {
        local $|++;
        my($image_data, $mime_type) = $image->out;
        binmode STDOUT;
        print "Content-type=image/$mime_type";
        print $image_data;
        close STDOUT;
    }

or something like that to print out image data to the web with a
proper content-type(make sure no other data are outputted before
sending content-type header), and then you can fetch it from the other
side with:
    <img src="/path/to/captcha.cgi?R=..." alt="" />

For me, the random number is generated from outside captcha.cgi, and
passed in with an encrypted query string(i.e. R=#### as in the above
sample). you can then decrypt it at the beginning of your Perl script
captcha.cgi.. If you like this approach, you need also check out CPAN
for some Crypt:: modules(I am using Crypt::RC4 for this).

BTW. with GD::ImageSecurity, you dont need any temporary file to save
the images....

Good luck,
lihao- Hide quoted text -

- Show quoted text -

Hey thanks but that doesnt help - looking for a simple script that
dumps to a DIRECTORY on WINDOWS captcha images and their code file.

Your code produces errors when I integrate it:

use GD::SecurityImage;
use HTML::Mason;

# Create a normal image
my $image = GD::SecurityImage->new(width => 80,
height => 30,
lines => 10,
gd_font => 'giant');
$your_random_str = '2345';
$image->random($your_random_str);
$image->create(normal => 'rect');
my($image_data, $mime_type, $random_number) = $image->out;

print " 1 $image_data 2 $mime_type 3 $random_number 4 $image
";

binmode STDOUT;
$m->clear_buffer();
$r->content_type("$image/$mime_type") ;
$m->print($image_data);
$m->flush_buffer();
$m->abort();

##### I Tried adding this but it doesnt help:
$filename1 = 'c:\tmp\test.png';
open(OUTFILE,">$filename1")|| die 'ERROR : external table not found :'.
$filename1."\n";
print OUTFILE $image_data;
# print OUTFILE out;

########
Results Errors:
1 5∞σ÷w?⌂«≤ ≈║±Lò☺- IEND«B`é 2 png 3 671027 4
GD::SecurityImage=HAS
H(0x18300bc) Can't call method "content_type" on an undefined value at
cap.pl li
ne 21. (same with clear_buffer and flush_buffer
 
L

lihao0129

I suppose you were in a web-context, so you need to print out the
result to STDOUT. you need also send out content-type header before
sending your image data.. what I did with HTML::Mason:
    my($image_data, $mime_type) = $image->out;
    binmode STDOUT;
    $m->clear_buffer();
    $r->content_type("image/$mime_type") ;
    $m->print($image_data);
    $m->flush_buffer();
    $m->abort();
If you were using plain-CGI, and your script filename is captcha.cgi,
then you probably can do things like:[sorry I have no experience with
plain CGI]
    {
        local $|++;
        my($image_data, $mime_type) = $image->out;
        binmode STDOUT;
        print "Content-type=image/$mime_type";
        print $image_data;
        close STDOUT;
    }
or something like that to print out image data to the web with a
proper content-type(make sure no other data are outputted before
sending content-type header), and then you can fetch it from the other
side with:
    <img src="/path/to/captcha.cgi?R=..." alt="" />
For me, the random number is generated from outside captcha.cgi, and
passed in with an encrypted query string(i.e. R=#### as in the above
sample). you can then decrypt it at the beginning of your Perl script
captcha.cgi.. If you like this approach, you need also check out CPAN
for some Crypt:: modules(I am using Crypt::RC4 for this).
BTW. with GD::ImageSecurity, you dont need any temporary file to save
the images....
Good luck,
lihao- Hide quoted text -
- Show quoted text -

Hey thanks but that doesnt help - looking for a simple script that
dumps to a DIRECTORY on WINDOWS captcha images and their code file.

Your code produces errors when I integrate it:

   use GD::SecurityImage;
use HTML::Mason;

   # Create a normal image
   my $image = GD::SecurityImage->new(width   => 80,
                                      height  => 30,
                                      lines   => 10,
                                      gd_font => 'giant');
$your_random_str = '2345';
      $image->random($your_random_str);
      $image->create(normal => 'rect');
   my($image_data, $mime_type, $random_number) = $image->out;

 print " 1  $image_data   2   $mime_type  3  $random_number 4 $image
";

    binmode STDOUT;
    $m->clear_buffer();
    $r->content_type("$image/$mime_type") ;
    $m->print($image_data);
    $m->flush_buffer();
    $m->abort();

I am not sure how you configured HTML::Mason with your site, but
before you use $m and $r objects under CGI, you should at least
instantiate them, otherwise they invoke ERRORs for undefined
variables... the point is sending out the correct content-type header,
and clearing non-related buffers before and after your image data, and
printing to STDOUT with binmode to generate the image on the fly.. no
need for a temporary file, this at least works under Linux box...

lihao
 
J

Jack

Hi there, I have installed every CPAN Captcha image verification known
and cant get any of them to do a simple task - output to a directorya
set of Captcha images with codes and the code file..you would think
its simple, I tried GD:SecurityImage and this does nothing:
 use GD::SecurityImage;
   # Create a normal image
   my $image = GD::SecurityImage->new(width   => 80,
                                      height  => 30,
                                      lines   => 10,
                                      gd_font => 'giant');
      $image->random($your_random_str);
      $image->create(normal => 'rect');
   my($image_data, $mime_type, $random_number) = $image->out;
It runs but you have no way of knowing "where" the images were
placed.  can anyone reply with a true to life working SIMPLE script
that just dumps the images and code file ??????
I suppose you were in a web-context, so you need to print out the
result to STDOUT. you need also send out content-type header before
sending your image data.. what I did with HTML::Mason:
    my($image_data, $mime_type) = $image->out;
    binmode STDOUT;
    $m->clear_buffer();
    $r->content_type("image/$mime_type") ;
    $m->print($image_data);
    $m->flush_buffer();
    $m->abort();
If you were using plain-CGI, and your script filename is captcha.cgi,
then you probably can do things like:[sorry I have no experience with
plain CGI]
    {
        local $|++;
        my($image_data, $mime_type) = $image->out;
        binmode STDOUT;
        print "Content-type=image/$mime_type";
        print $image_data;
        close STDOUT;
    }
or something like that to print out image data to the web with a
proper content-type(make sure no other data are outputted before
sending content-type header), and then you can fetch it from the other
side with:
    <img src="/path/to/captcha.cgi?R=..." alt="" />
For me, the random number is generated from outside captcha.cgi, and
passed in with an encrypted query string(i.e. R=#### as in the above
sample). you can then decrypt it at the beginning of your Perl script
captcha.cgi.. If you like this approach, you need also check out CPAN
for some Crypt:: modules(I am using Crypt::RC4 for this).
BTW. with GD::ImageSecurity, you dont need any temporary file to save
the images....
Good luck,
lihao- Hide quoted text -
- Show quoted text -
Hey thanks but that doesnt help - looking for a simple script that
dumps to a DIRECTORY on WINDOWS captcha images and their code file.
Your code produces errors when I integrate it:
   use GD::SecurityImage;
use HTML::Mason;
   # Create a normal image
   my $image = GD::SecurityImage->new(width   => 80,
                                      height  => 30,
                                      lines   => 10,
                                      gd_font => 'giant');
$your_random_str = '2345';
      $image->random($your_random_str);
      $image->create(normal => 'rect');
   my($image_data, $mime_type, $random_number) = $image->out;
 print " 1  $image_data   2   $mime_type  3  $random_number 4 $image
";
    binmode STDOUT;
    $m->clear_buffer();
    $r->content_type("$image/$mime_type") ;
    $m->print($image_data);
    $m->flush_buffer();
    $m->abort();

I am not sure how you configured HTML::Mason with your site, but
before you use $m and $r objects under CGI, you should at least
instantiate them, otherwise they invoke ERRORs for undefined
variables... the point is sending out the correct content-type header,
and clearing non-related buffers before and after your image data, and
printing to STDOUT with binmode to generate the image on the fly.. no
need for a temporary file, this at least works under Linux box...

lihao


##### I Tried adding this but it doesnt help:
$filename1 = 'c:\tmp\test.png';
open(OUTFILE,">$filename1")|| die 'ERROR : external table not found :'.
$filename1."\n";
print OUTFILE $image_data;
#  print OUTFILE out;
########
Results Errors:
1  5∞σ÷w?⌂«≤       ≈║±Lò☺-    IEND«B`é   2   png  3  671027 4
GD::SecurityImage=HAS
H(0x18300bc) Can't call method "content_type" on an undefined value at
cap.pl li
ne 21.  (same with clear_buffer and flush_buffer- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Does anyone have a working example of a script using Image::Magick (or
the GD::SecurityImage) or OTHER that outputs to a WINDOWS directory ?
This line just doesnt work from the above :

my($image_data, $mime_type) = $image->out;

Thank you,

Jack
 
J

Jack

Hi there, I have installed every CPAN Captcha image verification known
and cant get any of them to do a simple task - output to a directory a
set of Captcha images with codes and the code file..you would think
its simple, I tried GD:SecurityImage and this does nothing:
 use GD::SecurityImage;
   # Create a normal image
   my $image = GD::SecurityImage->new(width   => 80,
                                      height  => 30,
                                      lines   => 10,
                                      gd_font => 'giant');
      $image->random($your_random_str);
      $image->create(normal => 'rect');
   my($image_data, $mime_type, $random_number) = $image->out;
It runs but you have no way of knowing "where" the images were
placed.  can anyone reply with a true to life working SIMPLE script
that just dumps the images and code file ??????
I suppose you were in a web-context, so you need to print out the
result to STDOUT. you need also send out content-type header before
sending your image data.. what I did with HTML::Mason:
    my($image_data, $mime_type) = $image->out;
    binmode STDOUT;
    $m->clear_buffer();
    $r->content_type("image/$mime_type") ;
    $m->print($image_data);
    $m->flush_buffer();
    $m->abort();
If you were using plain-CGI, and your script filename is captcha.cgi,
then you probably can do things like:[sorry I have no experience with
plain CGI]
    {
        local $|++;
        my($image_data, $mime_type) = $image->out;
        binmode STDOUT;
        print "Content-type=image/$mime_type";
        print $image_data;
        close STDOUT;
    }
or something like that to print out image data to the web with a
proper content-type(make sure no other data are outputted before
sending content-type header), and then you can fetch it from the other
side with:
    <img src="/path/to/captcha.cgi?R=..." alt="" />
For me, the random number is generated from outside captcha.cgi, and
passed in with an encrypted query string(i.e. R=#### as in the above
sample). you can then decrypt it at the beginning of your Perl script
captcha.cgi.. If you like this approach, you need also check out CPAN
for some Crypt:: modules(I am using Crypt::RC4 for this).
BTW. with GD::ImageSecurity, you dont need any temporary file to save
the images....
Good luck,
lihao- Hide quoted text -
- Show quoted text -
Hey thanks but that doesnt help - looking for a simple script that
dumps to a DIRECTORY on WINDOWS captcha images and their code file.
Your code produces errors when I integrate it:
   use GD::SecurityImage;
use HTML::Mason;
   # Create a normal image
   my $image = GD::SecurityImage->new(width   => 80,
                                      height  => 30,
                                      lines   => 10,
                                      gd_font => 'giant');
$your_random_str = '2345';
      $image->random($your_random_str);
      $image->create(normal => 'rect');
   my($image_data, $mime_type, $random_number) = $image->out;
 print " 1  $image_data   2   $mime_type  3  $random_number 4 $image
";
    binmode STDOUT;
    $m->clear_buffer();
    $r->content_type("$image/$mime_type") ;
    $m->print($image_data);
    $m->flush_buffer();
    $m->abort();
I am not sure how you configured HTML::Mason with your site, but
before you use $m and $r objects under CGI, you should at least
instantiate them, otherwise they invoke ERRORs for undefined
variables... the point is sending out the correct content-type header,
and clearing non-related buffers before and after your image data, and
printing to STDOUT with binmode to generate the image on the fly.. no
need for a temporary file, this at least works under Linux box...
- Show quoted text -- Hide quoted text -
- Show quoted text -

Does anyone have a working example of a script using Image::Magick (or
the GD::SecurityImage) or OTHER that outputs to a WINDOWS directory ?
This line just doesnt work from the above :

my($image_data, $mime_type) = $image->out;

Thank you,

Jack- Hide quoted text -

- Show quoted text -

Hi no worries - I will find another solution .. no need for a response
- thanks all in perl land !
 
J

J. Gleixner

Of course not.. for one.. it should be:

my $filename1 = 'c:/tmp/test.png';

binmode( OUTFILE );

close( OUTFILE );

Nothing to do with your image. It's saying that $r and $m isn't defined.
Review using HTML::Mason.
Does anyone have a working example of a script using Image::Magick (or
the GD::SecurityImage) or OTHER that outputs to a WINDOWS directory ?
This line just doesnt work from the above :

my($image_data, $mime_type) = $image->out;

What do you mean by 'just doesnt work'????.. What are the errors?

What do you mean by 'outputs to a WINDOWS directory'?

If $image_data contains the binary for the image, and
you can open your OUTFILE, then you should be able to
write the data to it.

perldoc -f binmode

Of course, you're not going to be able to actually see the image
contained in that file, in an editor.

If you want to write the random number(s) generated, then write them
to another file, that'll make it easier for you to view that data.

First though, forget about HTML::Mason and get your code to work
outside of the Web Server. Once it does what you want, then
you only need to add the Web specific calls, already provided above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top