gimpycontroller.groovy
来自「一套用于生成各种图形验证码的库(Java)」· GROOVY 代码 · 共 103 行
GROOVY
103 行
import java.awt.Colorimport java.awt.Fontimport nl.captcha.Captchaimport nl.captcha.backgrounds.*import nl.captcha.gimpy.*import nl.captcha.text.renderer.*import nl.captcha.servlet.CaptchaServletUtil/*** Exercise the different gimpy renderers.***/class GimpyController { def final WIDTH = 200 def final HEIGHT = 50 def simple = { def captcha = new Captcha.Builder(WIDTH, HEIGHT) .addText() .gimp() .build() CaptchaServletUtil.writeImage(response, captcha.image) } def fisheye = { def captcha = new Captcha.Builder(WIDTH, HEIGHT) .addText() .gimp(new FishEyeGimpyRenderer(Color.RED, Color.BLUE)) .build() CaptchaServletUtil.writeImage(response, captcha.image) } def ripple = { def captcha = new Captcha.Builder(WIDTH, HEIGHT) .addText() .gimp(new RippleGimpyRenderer()) .build() CaptchaServletUtil.writeImage(response, captcha.image) } def shear = { def captcha = new Captcha.Builder(WIDTH, HEIGHT) .addText() .gimp(new ShearGimpyRenderer()) .build() CaptchaServletUtil.writeImage(response, captcha.image) } def shadow = { def captcha = new Captcha.Builder(WIDTH, HEIGHT) .addText() .gimp(new DropShadowGimpyRenderer()) .build() CaptchaServletUtil.writeImage(response, captcha.image) } def block = { def captcha = new Captcha.Builder(WIDTH, HEIGHT) .addText() .gimp(new BlockGimpyRenderer()) .build() CaptchaServletUtil.writeImage(response, captcha.image) } def blockbig = { def captcha = new Captcha.Builder(WIDTH, HEIGHT) .addText() .gimp(new BlockGimpyRenderer(5)) .build() CaptchaServletUtil.writeImage(response, captcha.image) } def example = { Captcha captcha = new Captcha.Builder(200, 50) .addText() .addBackground() .addNoise() .gimp() .addBorder() .build() CaptchaServletUtil.writeImage(response, captcha.image) } def multi = { def f = [new Font("Arial", Font.PLAIN, 48), new Font("Times", Font.PLAIN, 46)] def c = [Color.BLACK, Color.RED] def captcha = new Captcha.Builder(225, 75) // .addText(new ColoredEdgesWordRenderer(c, f)) .addText(new DefaultWordRenderer(c[1], f)) // .gimp(new DropShadowGimpyRenderer()) .addBackground(new SquigglesBackgroundProducer()) .addNoise() .gimp() .build() CaptchaServletUtil.writeImage(response, captcha.image) }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?