perl script to annoy spammers

Steve Poling sdpoling at attbi.com
Tue Feb 4 23:08:32 CST 2003


Consider the following prototype Perl script. It is not intended to be clever. Just get 
the job done. I'd appreciate any commentary. This has been tested under ActiveState/Win32, 
I'll test under Linux shortly. Thanks to Al and Chris and Paul.

#!/usr/bin/perl
#
#this program takes a string (email address) and generates a PNG file holding an image
#of that string. #the image is designed to annoying OCR programs. The purpose is to make 
#it relatively hard for spammers to scrape email addresses off webpages.
#
use GD;

if (@ARGV != 1) {
     die ("Usage: enter your email address that you want obscurified.\n"
         ,"e.g. addr2img.pl sdp\@i2k.com\n");
}
if (length($ARGV[0])==0){
     die ("Usage: You must enter a non-empty string as an email address.\n"
         ,"e.g. addr2img.pl sdp\@i2k.com\n");
}

$string = $ARGV[0];
$font = gdGiantFont;
$fontX = 9;
$fontY = 15;

$imageX = (1.2*$fontX)*(length($string)+2);
$imageY = $fontY*2;
$startX = $fontX/2 + rand()*$fontX;
$startY = rand()*$fontY/3;
$increment = ($imageX-$startX)/(length($string)+1);

$im = new GD::Image($imageX,$imageY);

$black = $im->colorAllocate(0,0,0);
$ivory = $im->colorAllocate(255,255,191);
$seagreen = $im->colorAllocate(191,255,255);

my $i;
my $toggle = 1;
for ($i=0;$i<length($string);$i++)
{
     if ($toggle==0)
     {
         $im->fill($startX,0,$ivory);
     }
     else
     {
         $im->fill($startX,0,$seagreen);
     }
     $toggle = 1 - $toggle;

     $char = substr($string,$i,1);
     $im->string($font,$startX + ($fontX/3)*rand(),$startY+($fontY/2)*rand(),$char,$black);
     $x = rand()*$fontX + $startX;
     for ($j=0;$j<$imageY;$j++)
     {
         $pixel = $im->getPixel($x,$j);
         $im->setPixel($x,$j, $black);
         if ($pixel==0)
         {
             $j = $imageY;
         }
     }
     $x = rand()*$fontX + $startX;
     for ($j=$imageY-1;$j>=0;$j--)
     {
         $pixel = $im->getPixel($x,$j);
         $im->setPixel($x,$j, $black);
         if ($pixel==0)
         {
             $j = 0;
         }
     }
     $startX += $increment;

}
$im->rectangle(0,0,$imageX-1,$imageY-1,$black);

# make sure we are writing to a binary stream
binmode STDOUT;

# Convert the image to PNG and print it on standard output
print $im->png;



Al Tobey wrote:
> What you want will be pretty easy with GD.  It is available on just
> about every default linux install.   I believe you can get it on
> ActiveState, too.  You may need to emply ImageMagick to get your bmp &
> gif files since GD only outputs jpg & png due to patent issues on gif.
> 
> http://www.cpan.org/authors/id/L/LD/LDS/GD-2.06.tar.gz
> http://www.cpan.org/authors/id/L/LD/LDS/GD-2.06.readme
> http://www.cpan.org/authors/id/M/MV/MVERB/GDTextUtil-0.83.tar.gz
> http://www.cpan.org/authors/id/M/MV/MVERB/GDTextUtil-0.83.readme
> 
> -Al Tobey
> 
> On Tue, 2003-02-04 at 11:08, Steve Poling wrote:
> 
>>Hey guys, it's me lowering the bar again.
>>
>>I'm looking for a Perl module that inputs a short bit of text and then outputs a bitmap
>>image thereof. Anybody know if such a critter exists?
>>
>>I have an insidious plan for thwarting spammers and this capability is the first step. If
>>you have ever purchased something via PayPal, you'll note that they make an image of some
>>authorization numbers and ask you to type in the authorization code. This prevents crooks
>>from writing programs that "scrape" the authorization code automatically.
>>
>>Why do I want to mess with this? I want to apply this technique to personal email
>>addresses. Goto http://steve.poling.info and you'll see my personal email address rendered
>>in a hard-to-scrape format. (Hehe, I hyperlink a sacrificial "spam-target" address in the
>>mailto target.) If I can get this module to work, I'll setup a freebie service to give my
>>friends nifty little hard-to-scrape gif files of their email addresses.
>>
>>My module would do this:
>>1) convert input text string to a bitmap.
>>2) randomly jizzle the individual letter positions
>>3) xor a patterned background
>>4) blast some random lines atop the letters
>>5) generate a bmp, gif, png output file.
>>6) mail the file to the specified address.
>>7) sell the address to spammers???? Horrors, NO!
>>
>>I figure there is probably an image processing Perl module that does most all these steps
>>individually. Does anybody know of any?
>>
>>I'd rather not do this in C++ as a matter of principle.
>>
>>smiles and cheers,
>>
>>steve




More information about the grand-rapids-pm-announce mailing list