请教新浪验证码的背景是咋样做的?
时间:2011-11-28
来源:互联网
新浪验证码的背景是咋样随机生成的?能否给个实例,谢谢
作者: xhfhyerdfbytrer 发布时间: 2011-11-28
就跟数字一样随机生成不行嘛
作者: PhpNewnew 发布时间: 2011-11-28
作者: xhfhyerdfbytrer 发布时间: 2011-11-28
<?php header ("Content-type: image/png"); session_start(); $gg = strtoupper(substr(rand(),0,2)); //rand生成随机数,substr截取函数,strtoupper字符串转大写,imagecolorallocate生成颜色,imagesetpixel画点函数,imagechar横向写字符 $_SESSION['bb']=$gg[0]+$gg[1]; $im = @imagecreate (59,25) or die ("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate ($im, 222, 222, 222); //设置干扰像素,防止被OCR for ($i=0;$i<=128;$i++) { $point_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255)); imagesetpixel($im,rand(2,128),rand(2,38),$point_color); } //逐个画上验证码字符 $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255)); $x = rand(5,10); $y = rand(5,10); imagechar ($im, 5, $x, $y, $gg[0], $text_color); $x = 20; imagechar ($im, 5, $x, $y, "+", $text_color); $x = 33; $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255)); imagechar ($im, 5, $x, $y, $gg[1], $text_color); $x = 45; imagechar ($im, 5, $x, $y, "=", $text_color); //输出PNG图像 imagepng ($im); imagedestroy ($im);
可以看看,改进改进。。
作者: ci1699 发布时间: 2011-11-28
PHP code
<?php
header ("Content-type: image/png");
session_start();
$gg = strtoupper(substr(rand(),0,2));
//rand生成随机数,substr截取函数,strtoupper字符串转大写,imagecolorallocate生成颜色,imagesetp……
作者: PhpNewnew 发布时间: 2011-11-28
绝招 一哭二闹三上吊 真快...
引用 3 楼 ci1699 的回复:
PHP code
<?php
header ("Content-type: image/png");
session_start();
$gg = strtoupper(substr(rand(),0,2));
//rand生成随机数,substr截取函数,strtoupper字符串转大写,im……
作者: ci1699 发布时间: 2011-11-28
作者: xhfhyerdfbytrer 发布时间: 2011-11-28
作者: kyzy_yy_pm 发布时间: 2011-11-28
作者: xhfhyerdfbytrer 发布时间: 2011-11-28
Header("Content-type: image/png"); $im = ImageCreate (200, 100); $col_blk = ImageColorAllocate($im, 0,0,0); $col_orn = ImageColorAllocate($im, 255,192,0); $col_yel = ImageColorAllocate($im, 255,255,0); $col_red = ImageColorAllocate($im, 255,0,0); $col_grn = ImageColorAllocate($im, 0,255,0); $col_blu = ImageColorAllocate($im, 0,0,255); ImageFilledRectangle($im,20,10,100,50,$col_blu); ImageFilledRectangle($im,5,40,50,90,$col_red); ImageFilledRectangle($im,40,80,100,95,$col_orn); ImageFilledRectangle($im,90,35,110,90,$col_yel); // 以上是第一种着色。直接绘制矩形。 // 我故意用四个不同颜色的矩形围起一小块区域, ImageFill($im,70,70,$col_grn); // 这是第二种着色。 ImageRectangle($im,120,40,190,90,$col_grn); // 暂且画一个矩形来做框吧。事实上任何样子的边界都可以做框。 ImageFilltoBorder($im,130,50,$col_grn,$col_orn); // 把绿色矩形框内涂成橙色。 // 只要指定的点位于这个“框”的范围内即可,与该点在区域内的位置无关。 // 这个函数其实是这样工作的: // 从指定的点开始,向外,寻找指定颜色的边界,如果找到,则停止, // 找不到,就把途经的点涂成需要的颜色。 ImagePNG($im); ImageDestroy($im);
画方框例子
作者: ci1699 发布时间: 2011-11-28
是动态生成的,绝对不是背景图
你怎么知道是不是背景图呢?
作者: kyzy_yy_pm 发布时间: 2011-11-28
作者: xhfhyerdfbytrer 发布时间: 2011-11-28
PHP code
header ("Content-type: image/png"); session_start(); $gg = strtoupper(substr(rand(),0,2)); //rand生成随机数,substr截取函数,strtoupper字符串转大写,imagecolorallocate生成颜色,imagesetpixel画点函数,imagechar横向写字符 $_SESSION['bb']=$gg[0]+$gg[1]; $im = @imagecreate (500,80) or die ("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate ($im, 222, 222, 222); //设置干扰像素,防止被OCR //for ($i=0;$i<=128;$i++) for ($i=0;$i<=10;$i++) { $point_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255)); $cx = rand(5, 450); $cy = rand(5, 75); $w = rand(5, 70); $h = rand(5, 20); $s = 1.25; $e = 1.25; $color = 120; imagearc ( $im , $cx , $cy , $w , $h , $s , $e , $color ); // imagesetpixel($im,rand(2,500),rand(2,80),$point_color); } //逐个画上验证码字符 $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255)); //数字1 $x = rand(5,100); $y = rand(5,40); imagechar ($im, 5, $x, $y, $gg[0], $text_color); //+ $x = 150; imagechar ($im, 5, $x, $y, "+", $text_color); //数字2 $x = rand(260,380); $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255)); imagechar ($im, 5, $x, $y, $gg[1], $text_color); // = $x = 400; imagechar ($im, 5, $x, $y, "=", $text_color); //输出PNG图像 imagepng ($im); imagedestroy ($im);
作者: kyzy_yy_pm 发布时间: 2011-11-28
header ("Content-type: image/png"); session_start(); $gg = strtoupper(substr(rand(),0,2)); //rand生成随机数,substr截取函数,strtoupper字符串转大写,imagecolorallocate生成颜色,imagesetpixel画点函数,imagechar横向写字符 $_SESSION['bb']=$gg[0]+$gg[1]; $im = @imagecreate (500,80) or die ("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate ($im, 222, 222, 222); //设置干扰像素,防止被OCR //for ($i=0;$i<=128;$i++) for ($i=0;$i<=10;$i++) { $x1 = rand(-5, 490); $y1 = rand(-5, 75); $x2 = rand(300, 600); $y2 = rand(40, 90); $color = rand(10, 255); imagefilledrectangle($im, $x1, $y1, $x2, $y2, $color); // imagefilledarc($im, $cx, $cy, $w, $h, 10, $s, $e, $color); } //逐个画上验证码字符 $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255)); //数字1 $x = rand(5,100); $y = rand(5,40); imagechar ($im, 5, $x, $y, $gg[0], $text_color); //+ $x = 150; imagechar ($im, 5, $x, $y, "+", $text_color); //数字2 $x = rand(260,380); $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255)); imagechar ($im, 5, $x, $y, $gg[1], $text_color); // = $x = 400; imagechar ($im, 5, $x, $y, "=", $text_color); //输出PNG图像 imagepng ($im); imagedestroy ($im);
这个你调调吧,就是这个了
作者: kyzy_yy_pm 发布时间: 2011-11-28
PHP code
header ("Content-type: image/png");
session_start();
$gg = strtoupper(substr(rand(),0,2));
//rand生成随机数,substr截取函数,strtoupper字符串转大写,imagecolorallocate生成颜色,imagesetpixel画点函数……
作者: ci1699 发布时间: 2011-11-28
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28