001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.commons.img; 020 021import java.awt.Color; 022import java.awt.image.BufferedImage; 023import java.io.File; 024import java.io.FileOutputStream; 025import java.io.IOException; 026 027public class TestCaptcha { 028 029 public static void main(String[] args) throws IOException { 030 Captcha captcha=new Captcha(); 031 032 // generate captcha image 033 BufferedImage image = captcha.generate( 034 Captcha.randomString(10), // Text 035 450, // width 036 70, // height 037 new String[]{"arial","courier new"}, // fonts 038 true, // use anti alias 039 Color.BLACK, // font color 040 45, // font size 041 Captcha.DIFFICULTY_HIGH // difficulty 042 ); 043 044 // write out captcha image as a png file 045 FileOutputStream fos = new FileOutputStream(new File("/Users/mic/temp/captcha.png")); 046 Captcha.writeOut(image, fos, "png"); 047 048 // write out captcha image as a jpg file 049 fos = new FileOutputStream(new File("/Users/mic/temp/captcha.jpg")); 050 Captcha.writeOut(image, fos, "jpg"); 051 052 } 053}