- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章php 验证码(倾斜,正弦干扰线,黏贴,旋转)由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
好久没有写帖子了。一直忙着新的项目。 最近,做验证码程序,一直想做一个简洁大方,自动识别比较困难的。 通过这些时候整理搜集,发现一般做法有以下几种方案: 1、字体变型 (一般通过算法,进行扭曲,比较有代表性就是:http://code.google.com/p/cool-php-captcha/ 。
2、字体黏贴 (这里面以qq验证码为代表了,目前网上还是很难找到,破解qq验证码的) 。
3、干扰线,噪点 (这种识别起来相当容易,很容易被程序自动化识别) 对于上面提到,第1,2 二种方法,在识别时候,是比较困难的。个人比较喜欢第二种方法,感觉看起来不是很费力。而扭曲的文字,总觉得怪怪的。 哈哈,纯粹个人喜好了。 实现代码:
复制代码 代码如下
<?php /** *带文字旋转,倾斜,黏贴,加正弦干扰线验证码* *@version 0.1 *@author http://www.cnblogs.com/chengmo *@copyright 程默 QQ:8292669 */ class Utils_Caption { var $Width = 60; //图片宽 var $Height = 30; //图片高 var $Length = 4; //验证码位数 var $BgColor = "#FFFFFF"; //背景色 var $TFonts = array("font.ttf"); var $TFontSize=array(17,20); //字体大小范围 var $TFontAngle=array(-20,20); //旋转角度 var $Chars = "0123456789"; //验证码范围(字母数字) var $Code = array(); //验证码 var $Image = ""; //图形对象 var $FontColors=array('#f36161','#6bc146','#5368bd'); //字体颜色,红绿蓝 var $TPadden = 0.75;///字符间距,多少个字符 var $Txbase = 5;///x轴两边距离 var $Tybase =5 ;///y轴两边距离 var $TLine =true; ///画干扰线 public function RandRSI() ///生成验证码 { $this->TFontAngle=range($this->TFontAngle[0],$this->TFontAngle[1]); $this->TFontSize=range($this->TFontSize[0],$this->TFontSize[1]); $arr=array(); $Chars=$this->Chars; $TFontAngle=$this->TFontAngle; $TFontSize=$this->TFontSize; $FontColors=$this->FontColors; $code=""; $font=dirname(__FILE__)."/font/".$this->TFonts[0]; $charlen=strlen($Chars)-1; $anglelen=count($TFontAngle)-1; // 角度范围 $fontsizelen=count($TFontSize)-1; // 角度范围 $fontcolorlen=count($FontColors)-1; // 角度范围 for($i=0;$i<$this->Length;$i++) ///得到字符与颜色 { $char=$Chars[rand(0,$charlen)]; ///得到字符 $angle=$TFontAngle[rand(0,$anglelen)]; ///旋转角度 $fontsize=$TFontSize[rand(0,$fontsizelen)]; ///字体大小 $fontcolor=$FontColors[rand(0,$fontcolorlen)]; ///字体大小 $bound=$this->_calculateTextBox($fontsize,$angle,$font,$char); ///得到范围 $arr[]=array($fontsize,$angle,$fontcolor,$char,$font,$bound); ///得到矩形框 $code.=$char; } $this->Code=$arr; //验证码 return $code; } public function Draw() ///画图 { if(empty($this->Code)) $this->RandRSI(); $codes=$this->Code; ///用户验证码 $wh=$this->_getImageWH($codes); $width=$wh[0]; $height=$wh[1]; ///高度 $this->Width=$width; $this->Height=$height; $this->Image = imageCreate( $width, $height ); $image=$this->Image; $back = $this->_getColor2($this->_getColor( $this->BgColor)); ///背景颜色 imageFilledRectangle($image, 0, 0, $width, $height, $back); ///填充背景 $TPadden=$this->TPadden; $basex=$this->Txbase; $color=null; foreach ($codes as $v) ///逐个画字符 { $bound=$v[5]; $color=$this->_getColor2($this->_getColor($v[2])); imagettftext($image, $v[0], $v[1], $basex, $bound['height'],$color , $v[4], $v[3]); $basex=$basex+$bound['width']*$TPadden-$bound['left'];///计算下一个左边距 } $this->TLine?$this->_wirteSinLine($color,$basex):null; ///画干扰线 header("Content-type: image/png"); imagepng( $image); imagedestroy($image); } /** *通过字体角度得到字体矩形宽度* * * @param int $font_size 字体尺寸 * @param float $font_angle 旋转角度 * @param string $font_file 字体文件路径 * @param string $text 写入字符 * @return array 返回长宽高 */ private function _calculateTextBox($font_size, $font_angle, $font_file, $text) { $box = imagettfbbox($font_size, $font_angle, $font_file, $text); $min_x = min(array($box[0], $box[2], $box[4], $box[6])); $max_x = max(array($box[0], $box[2], $box[4], $box[6])); $min_y = min(array($box[1], $box[3], $box[5], $box[7])); $max_y = max(array($box[1], $box[3], $box[5], $box[7])); return array( 'left' => ($min_x >= -1) ? -abs($min_x + 1) : abs($min_x + 2), 'top' => abs($min_y), 'width' => $max_x - $min_x, 'height' => $max_y - $min_y, 'box' => $box ); } private function _getColor( $color ) //#ffffff { return array(hexdec($color[1].$color[2]),hexdec($color[3].$color[4]),hexdec($color[5].$color[6])); } private function _getColor2( $color ) //#ffffff { return imagecolorallocate ($this->Image, $color[0], $color[1], $color[2]); } private function _getImageWH($data) { $TPadden=$this->TPadden; $w=$this->Txbase; $h=0; foreach ($data as $v) { $w=$w+$v[5]['width']*$TPadden-$v[5]['left']; $h=$h>$v[5]['height']?$h:$v[5]['height']; } return array(max($w,$this->Width),max($h,$this->Height)); } //画正弦干扰线 private function _wirteSinLine($color,$w) { $img=$this->Image; $h=$this->Height; $h1=rand(-5,5); $h2=rand(-1,1); $w2=rand(10,15); $h3=rand(4,6); for($i=-$w/2;$i<$w/2;$i=$i+0.1) { $y=$h/$h3*sin($i/$w2)+$h/2+$h1; imagesetpixel($img,$i+$w/2,$y,$color); $h2!=0?imagesetpixel($img,$i+$w/2,$y+$h2,$color):null; } } } 。
外带字体: font.ttf ,一个简单粗体文件.
说明:先看下运行效果吧,大家也不要忙着复制运行了.
主要特点是:旋转,然后黏贴,干扰线是线粗细可以变,然后正弦波形可以变化。 比较复杂是:calculateTextBox 这个函数,这个是得到字符旋转后的宽度高度。 demo
复制代码 代码如下
$rsi = new Utils_Caption(); $rsi->TFontSize=array(15,17); $rsi->Width=50; $rsi->Height=25; $code = $rsi->RandRSI(); session_start(); $_SESSION["CHECKCODE"] = $code; $rsi->Draw(),
好了,就写这么些了,代码还有很多不足之处.
。
最后此篇关于php 验证码(倾斜,正弦干扰线,黏贴,旋转)的文章就讲到这里了,如果你想了解更多关于php 验证码(倾斜,正弦干扰线,黏贴,旋转)的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
...沮丧。我希望我的游戏仅在横向模式下运行。我已将适当的键/值添加到 Info.plist 文件中,以强制设备方向在启动时正确。 我现在正在尝试旋转 OpenGL 坐标空间以匹配设备的坐标空间。我正
我如何创建一个旋转矩阵,将 X 旋转 a,Y 旋转 b,Z 旋转 c? 我需要公式,除非您使用的是 ardor3d api 的函数/方法。 矩阵是这样设置的 xx, xy, xz, yx, yy, y
假设我有一个包含 3 个 vector 的类(一个用于位置,一个用于缩放,一个用于旋转)我可以使用它们生成一个变换矩阵,该矩阵表示对象在 3D 空间中的位置、旋转和大小。然后我添加对象之间的父/子关系
所以我只是在玩一个小的 javascript 游戏,构建一个 pacman 游戏。你可以在这里看到它:http://codepen.io/acha5066/pen/rOyaPW 不过我对旋转有疑问。你
在我的应用程序中,我有一个 MKMapView,其中显示了多个注释。 map 根据设备的航向旋转。要旋转 map ,请执行以下语句(由方法 locationManager 调用:didUpdateHe
使用此 jquery 插件时:http://code.google.com/p/jqueryrotate/wiki/Documentation我将图像旋转 90 度,无论哪个方向,它们最终都会变得模糊
我有以下代码:CSS: .wrapper { margin:80px auto; width:300px; border:none; } .square { widt
我只想通过小部件的轴移动图像并围绕小部件的中心旋转(就像任何数字绘画软件中的 Canvas ),但它围绕其左顶点旋转...... QPainter p(this); QTransform trans;
我需要先旋转图像,然后再将其加载到 Canvas 中。据我所知,我无法使用 canvas.rotate() 旋转它,因为它会旋转整个场景。 有没有好的JS方法来旋转图片? [不依赖于浏览器的方式] 最
我需要知道我的 Android 设备屏幕何时从一个横向旋转到另一个横向(rotation_90 到 rotation_270)。在我的 Android 服务中,我重新实现了 onConfigurati
**摘要:**本篇文章主要讲解Python调用OpenCV实现图像位移操作、旋转和翻转效果,包括四部分知识:图像缩放、图像旋转、图像翻转、图像平移。 本文分享自华为云社区《[Python图像处理] 六
我只是在玩MTKView中的模板设置;并且,我一直在尝试了解以下内容: 相机的默认位置。 使用MDLMesh和MTKMesh创建基元时的默认位置。 为什么轮换还涉及翻译。 相关代码: matrix_f
我正在尝试使用包 dendexend 创建一个树状图。它创建了非常好的 gg 树状图,但不幸的是,当你把它变成一个“圆圈”时,标签跟不上。我将在下面提供一个示例。 我的距离对象在这里:http://s
我想将一个完整的 ggplot 对象旋转 90°。 我不想使用 coord_flip因为这似乎会干扰 scale="free"和 space="free"使用刻面时。 例如: qplot(as.fac
我目前可以通过首先平移到轴心点然后执行旋转最后平移回原点来围绕轴心点旋转。在我的例子中,我很容易为肩膀做到这一点。但是,我不知道如何为前臂添加绕肘部的旋转。 我已经尝试了以下围绕肘部旋转的前臂: 平移
我想使用此功能旋转然后停止在特定点或角度。现在该元素只是旋转而不停止。代码如下: $(function() { var $elie = $("#bkgimg");
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
我正在尝试创建一个非常简单的关键帧动画,其中图形通过给定的中点从一个角度旋转到另一个角度。 (目的是能够通过大于 180 度的 OBTUSE 弧角来制作旋转动画,而不是让动画“作弊”并走最短路线,即通
我需要旋转 NSView 实例的框架,使其宽度变为其高度,其高度变为其宽度。该 View 包含一个字符串,并且该字符串也被旋转,这一点很重要。 我查看了 NSView 的 setFrameRotati
我正在编写一个脚本,用于在 javascript 中旋转/循环浏览图像,同时遵守循环浏览图像的次数限制。我所拥有的如下: var delay = 3000; //6000 = change to
我是一名优秀的程序员,十分优秀!