Adding new image generators

0 views
Skip to first unread message

Nick Murdoch

unread,
Oct 26, 2007, 5:10:41 AM10/26/07
to TGCaptcha
Hi,

I posted this a couple of days ago but it doesn't seem to have shown
up in the group yet...

I'm trying to add my own image generator to TG Captcha, as the two
built-in ones have turned out to be unsuitable for purpose. I've had a
look through the code for this project, and it seems that I should be
able to add one in pretty easily by adding a module into plugins/.

However, ideally I would like to be able to create a separate package
altogether and have TGCaptcha be able to pick it up from python's
standard site-packages (or anywhere else in the path for that matter),
to save the hassle of having to maintain a branch of this project.

Is this possible to do?

Thanks,

Patrick Lewis

unread,
Oct 30, 2007, 10:36:57 AM10/30/07
to TGCaptcha
Apologies that it took so long for this to show up. I don't know what
happened with the group; today was the first time I got notification
that you had posted.

Yes, you should be able to extend TGCaptcha to use your own code,
independent of the TGCaptcha package. If you look in TGCaptcha's
setup.py, you will see an entry point for
[tgcaptcha.jpeg_generators]. In your new package, you will need to
define that entry point and point it to an appropriate method that
returns a jpeg.

The interface for the plugin is pretty simple[1]. The function expects
to receive some text and a standard 'file' object; your code will need
to render the text parameter and save it to the file.

Then, in your web application, change the tgcaptcha.cfg
'tgcaptcha.jpeg_generator' variable to point to your new entry point.

Hope this helps, if you run into problems please don't hesitate to
ask; I will make special effort to check back periodically.

[1] example: http://tgcaptcha.googlecode.com/svn/trunk/tgcaptcha/plugins/image/mcdermott.py

Nick Murdoch

unread,
Jan 7, 2008, 11:43:04 AM1/7/08
to tgca...@googlegroups.com
Hi Patrick,

Thanks for your help! I finally got around to trying this out, making a
clone of the McDermott generator inside its own package, and after
reading the setuptools docs on entry points, it all came together really
well!

Thanks,

Nick

Reply all
Reply to author
Forward
0 new messages