package com.backendsys.config.Kaptcha;

import com.google.code.kaptcha.BackgroundProducer;
import com.google.code.kaptcha.util.Configurable;

import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

/**
 * @description: 去除验证码背景颜色
 * @author: DT
 * @date: 2021/5/19 22:54
 * @version: v1.0
 */
public class KaptchaNoBackhround extends Configurable implements BackgroundProducer {

    public KaptchaNoBackhround(){
    }

    @Override
    public BufferedImage addBackground(BufferedImage bufferedImage) {
        int width = 120;
        int height = 45;
        BufferedImage imageWithBackground = new BufferedImage(width, height, 1);
        Graphics2D graph = (Graphics2D)imageWithBackground.getGraphics();
        graph.fill(new Rectangle2D.Double(0.0D, 0.0D, (double)width, (double)height));
        graph.drawImage(bufferedImage, 0, 0, null);
        return imageWithBackground;
    }
}
