Create Unique Fonts For Your Captchas
by Antone Roundy | 2 Comments | Misc Website Scripts
I recently noticed that the page I was linking to for fonts for my PHP & GD powered captcha script had been taken down, so I went looking for another solution for my users. What I found was even better than another place to get fonts.
GD FontMaker is a script by Howard Yeend that converts PNG images into GD font format. Since it's GPL software, I was able to modify it to make it a little more powerful and easier to use. Download my version here.
The great thing about this script is that it enables you to generate your own unique fonts to use in your captchas. Of course, uniqueness is no guarantee that OCR won't be able to crack your captcha, but it's certainly better than using the same old fonts as everyone else.
The first font I created with this script was apparently a little too easy to crack. I replaced some of the fonts I'd been using before because I periodically get complaints from people who've tried multiple times and can't solve them. Over the next few days, the amount of comment spam in my blogs increased noticeably. It wasn't an explosion, but it was annoying.
So I whipped up a few more fonts by applying filters to the first one (using the GIMP). That seems to have solved the problem.
August 20th, 2009 at 2:02 am
Hi!
Thanks for the kind words about my script. T'was written a long time ago, and I'm glad you found a use for it.
I like your use of pack() for the header.
I noticed you changed the inner loop from using $c to calling chr(). In this kind of application the difference is absolutely trivial, and it's probably worth doing it your way for clarity of code, but I ran some benchmarks looping 100000 times, first running $d .= chr(255); and in the second loop running $d .= $c; where $c=chr(255); Results below:
chr() in loop: 0.173...
$c in loop: 0.031...
Now, like I said it's a totally trivial difference and not really worth thinking about, although it will loop 23400 times assuming 26 characters @ 30x30, so there might be a marginally noticeable difference (benchmarks for 23400: 0.045... vs 0.007...)
But I thought I'd just explain why I did it that way :0)
I also wrote a captcha script you might like to take a look over: http://www.puremango.co.uk/2005/04/php_captcha_script_113/
Have fun!
September 8th, 2009 at 3:22 pm
Howard,
I confess, I picked up the pack() code from a Perl font making script somewhere. Looking at your code, I was guessing that's how numbers bigger than 255 would be handled, so I went looking for confirmation and found that.
Thanks for writing the original code.
Antone