On Fri, Nov 14, 2008 at 7:53 AM, <xor at freenetproject.org> wrote:
> Author: xor
> Date: 2008-11-13 23:53:07 +0000 (Thu, 13 Nov 2008)
> New Revision: 23546
>
> Modified:
> trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java
> Log:
> Implement captcha factory based on kaptcha.
kaptcha need ` -Djava.awt.headless=true ' on linux
> Modified: trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java
> ===================================================================
> --- trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java 2008-11-13
> 23:52:20 UTC (rev 23545)
> +++ trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java 2008-11-13
> 23:53:07 UTC (rev 23546)
> @@ -5,8 +5,16 @@
> */
> package plugins.WoT.introduction.captcha;
>
> +import java.awt.image.BufferedImage;
> +import java.io.ByteArrayOutputStream;
> +import java.io.IOException;
> +
> +import javax.imageio.ImageIO;
> +
> +import plugins.WoT.Identity;
> import plugins.WoT.introduction.IntroductionPuzzle;
> import plugins.WoT.introduction.IntroductionPuzzleFactory;
> +import plugins.WoT.introduction.captcha.kaptcha.impl.DefaultKaptcha;
>
> /**
> * First implementation of a captcha factory.
> @@ -21,8 +29,19 @@
> */
> public class CaptchaFactory1 implements IntroductionPuzzleFactory {
>
> - public IntroductionPuzzle generatePuzzle() {
> - return null;
> + public IntroductionPuzzle generatePuzzle(Identity inserter, int
> index) throws IOException {
> + ByteArrayOutputStream out = new ByteArrayOutputStream(10 *
> 1024);
> + try {
> + DefaultKaptcha captcha = new DefaultKaptcha();
> + String text = captcha.createText();
> + BufferedImage img = captcha.createImage(text);
> + /* TODO: find out the maximum size of the captchas
> and put it here */
> +
> + ImageIO.write(img, "jpg", out);
> + return new IntroductionPuzzle(inserter, "image/jpeg",
> out.toByteArray(), text, index);
> + }
> + finally {
> + out.close();
> + }
> }
> -
> }
>
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>