Atiitt 圖片影象驗證碼生成法原理 目錄 1.1. 常見的最簡單圖片驗證碼是利用影象api把隨機數文字轉影象 1 1.2. 常見較為複雜圖片驗證碼的方法 ( 鏤空文字 打散 干擾線 文字扭曲
Atiitt 圖片影象驗證碼生成法原理
目錄
1.1. 常見的最簡單圖片驗證碼是利用影象api把隨機數文字轉影象 1
1.2. 常見較為複雜圖片驗證碼的方法 ( 鏤空文字 打散 干擾線 文字扭曲 粘連 膨脹,填充 ) 1
-
- 常見較為複雜圖片驗證碼的方法 ( 鏤空文字 打散 干擾線 文字扭曲 粘連 膨脹,填充 旋轉)
- 常見較為複雜圖片驗證碼的方法 ( 鏤空文字 打散 干擾線 文字扭曲 粘連 膨脹,填充 旋轉)
/atiplat_cms/src/com/attilax/captcha/CapchGene.java
public void geneCapch(OutputStream os) throws IOException
{
//設定字母的大小,大小
int width=600, height=200;
int fontSiz = 50;
Font mFont = new Font("Times New Roman", Font.BOLD, fontSiz);
// response.setHeader("
// response.setHeader("Cache-Control","no-cache");
// response.setDateHeader("Expires", 0);
//表明生成的響應是圖片
// response.setContentType("image/jpeg");
// 100*18
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
//set boder
g.setColor(new Color(102,102,102));
g.drawRect(0, 0, width-1, height-1);
//set bg
g.setColor(getRandColor(200,250));
// g.fillRect(1, 1, width-1, height-1);
g.fillRect(0,0, width, height);
g.setFont(mFont);
g.setColor(getRandColor(160,200));
Random random = new Random();
//畫隨機線
// for (int i=0;i<155;i++)
// {
// int x = random.nextInt(width - 1);
// int y = random.nextInt(height - 1);
// int xl = random.nextInt(6) + 1;
// int yl = random.nextInt(12) + 1;
// g.drawLine(x,y,x + xl,y + yl);
// }
//
// //從另一方向畫隨機線
// for (int i = 0;i < 70;i++)
// {
// int x = random.nextInt(width - 1);
// int y = random.nextInt(height - 1);
// int xl = random.nextInt(12) + 1;
// int yl = random.nextInt(6) + 1;
// g.drawLine(x,y,x - xl,y - yl);
// }
//生成隨機數,並將隨機數字轉換為字母
String sRand="";
for (int i=0;i<6;i++)
{
int itmp = random.nextInt(26) + 65;
char ctmp = (char)itmp;
sRand += String.valueOf(ctmp);
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(String.valueOf(ctmp),fontSiz*i+10,fontSiz);
}
// HttpSession session = request.getSession(true);
// session.setAttribute("rand",sRand);
// g.dispose();
ImageIO.write(image, "JPEG", os);
}
photoshop製作鏤空文字
驗證碼的前世今生(前世篇) - 阿里聚安全 - 部落格園.html
atitit安全的驗證碼
Atitit 圖片 驗證碼生成attilax總結