/**

* 图像操作类

*/

class helper_image

{

/**

* 生成图像验证码

* @static

* @access public

* @param string $length 位数

* @param string $mode 类型

* @param string $type 图像格式

* @param string $width 宽度

* @param string $height 高度

* @return string

*/

static function buildImageVerify($length=4, $mode=1, $type='png', $width=48, $height=22, $verifyName='verify') {

ob_clean();

$randval = helper_string::randString($length, $mode);

$session = Yaf_Session::getInstance();

$tmp = strtoupper($randval);

$session->$verifyName = $tmp;

$width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;

if ($type != 'gif' && function_exists('imagecreatetruecolor')) {

$im = imagecreatetruecolor($width, $height);

} else {

$im = imagecreate($width, $height);

}

$r = Array(225, 255, 255, 223);

$g = Array(225, 236, 237, 255);

$b = Array(225, 236, 166, 125);

$key = mt_rand(0, 3);

$backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]); //背景色(随机)

$borderColor = imagecolorallocate($im, 100, 100, 100); //边框色

imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);

imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);

$stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));

// 干扰

for ($i = 0; $i < 10; $i++) {

imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $stringColor);

}

for ($i = 0; $i < 25; $i++) {

imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $stringColor);

}

for ($i = 0; $i < $length; $i++) {

imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval{$i}, $stringColor);

}

helper_image::output($im, $type);

}

static function output($im, $type='png', $filename='') {

header("Content-type: image/" . $type);

$ImageFun = 'image' . $type;

if (empty($filename)) {

$ImageFun($im);

} else {

$ImageFun($im, $filename);

}

imagedestroy($im);

}

static function echo_validate_image( $config = array(), $verifyName)

{

$config = array(

'font_size' => 14,

'img_height' => 24,

'word_type' => 2, // 1:数字 2:英文

'img_width' => 68,

'use_boder' => TRUE,

'font_file' => ROOT_PATH.'/public/admin/image/ggbi.ttf',

'filter_type' => 5);

//主要参数

$font_size = isset($config['font_size']) ? $config['font_size'] : 14;

$img_height = isset($config['img_height']) ? $config['img_height'] : 24;

$img_width = isset($config['img_width']) ? $config['img_width'] : 68;

$font_file = isset($config['font_file']) ? $config['font_file'] : ROOT_PATH.'/public/admin/image/ggbi.ttf';

$use_boder = isset($config['use_boder']) ? $config['use_boder'] : TRUE;

$filter_type = isset($config['filter_type']) ? $config['filter_type'] : 0;

//创建图片,并设置背景色

$im = @imagecreate($img_width, $img_height);

imagecolorallocate($im, 255,255,255);

//文字随机颜色

$fontColor[] = imagecolorallocate($im, 0x15, 0x15, 0x15);

$fontColor[] = imagecolorallocate($im, 0x95, 0x1e, 0x04);

$fontColor[] = imagecolorallocate($im, 0x93, 0x14, 0xa9);

$fontColor[] = imagecolorallocate($im, 0x12, 0x81, 0x0a);

$fontColor[] = imagecolorallocate($im, 0x06, 0x3a, 0xd5);

//获取随机字符

$rndstring = '';

for($i=0; $i<4; $i++)

{

if ($config['word_type'] == 1)

{

$c = chr(mt_rand(48, 57));

} else if($config['word_type'] == 2)

{

$c = chr(mt_rand(65, 90));

if( $c=='I' ) $c = 'P';

if( $c=='O' ) $c = 'N';

}

$rndstring .= $c;

}

//$_SESSION['securimage_code_value'] = strtolower($rndstring);

$session = Yaf_Session::getInstance();

$tmp = strtoupper($rndstring);

$session->$verifyName = $tmp;

$rndcodelen = strlen($rndstring);

//背景横线

$lineColor1 = imagecolorallocate($im, 0xda, 0xd9, 0xd1);

for($j=3; $j<=$img_height-3; $j=$j+3)

{

imageline($im, 2, $j, $img_width - 2, $j, $lineColor1);

}

//背景竖线

$lineColor2 = imagecolorallocate($im, 0xda,0xd9,0xd1);

for($j=2;$j<100;$j=$j+6)

{

imageline($im, $j, 0, $j+8, $img_height, $lineColor2);

}

//画边框

if( $use_boder && $filter_type == 0 )

{

$bordercolor = imagecolorallocate($im, 0x9d, 0x9e, 0x96);

imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $bordercolor);

}

//输出文字

$lastc = '';

for($i=0;$i

{

$bc = mt_rand(0, 1);

$rndstring[$i] = strtoupper($rndstring[$i]);

$c_fontColor = $fontColor[mt_rand(0,4)];

$y_pos = $i==0 ? 4 : $i*($font_size+2);

$c = mt_rand(0, 15);

@imagettftext($im, $font_size, $c, $y_pos, 19, $c_fontColor, $font_file, $rndstring[$i]);

$lastc = $rndstring[$i];

}

//图象效果

switch($filter_type)

{

case 1:

imagefilter ( $im, IMG_FILTER_NEGATE);

break;

case 2:

imagefilter ( $im, IMG_FILTER_EMBOSS);

break;

case 3:

imagefilter ( $im, IMG_FILTER_EDGEDETECT);

break;

default:

break;

}

header("Pragma:no-cache\r\n");

header("Cache-Control:no-cache\r\n");

header("Expires:0\r\n");

//输出特定类型的图片格式,优先级为 gif -> jpg ->png

//dump(function_exists("imagejpeg"));

if(function_exists("imagejpeg"))

{

header("content-type:image/jpeg\r\n");

imagejpeg($im);

}

else

{

header("content-type:image/png\r\n");

imagepng($im);

}

imagedestroy($im);

exit();

}

}

?>

一键复制

编辑

Web IDE

原始数据

按行查看

历史

image.helper.php,image.php相关推荐

  1. 通用权限管理组件使用说明书V3.0 错误校正 感谢自由软件职业者Helper(767870484)...

    有时候,真想做个像样的东西出来,但是往往各方面的能力都不够,这么多人,Helper(767870484)仔细认真的阅读了这个帮助手册.并给给于了指正,在这里非常感谢,你的劳动成果已经被通用权限管理积累 ...

  2. 爬虫之谷歌浏览器xpath helper插件的安装和使用

    爬虫之谷歌浏览器xpath helper插件的安装和使用 要想利用lxml模块提取数据,需要我们掌握xpath语法规则.接下来我们就来了解一下xpath helper插件,它可以帮助我们练习xpath ...

  3. 在Asp.net MVC framework中使用扩展方法创建Html Helper

    HtmlHelper提供了一些帮助的方法返回一个字符串来生成html. 在System.Web.Mvc.Html命称空间下有一些表单,控件,局部视图Helper方法.我将创建一个生成标签<inp ...

  4. 报错解决:ad NaCl helper startup ack (0 bytes)

    此文首发于我的个人博客:报错解决:ad NaCl helper startup ack (0 bytes) - zhang0peter的个人博客 在使用pyppeteer操作Chrome进行爬虫时,大 ...

  5. MVC Razor:自定义Helper方法

    在使用自定义Helper方法时,开始我试了很多次都不成功一直报错"找不到WebMatrix.WebData.dll.WebMatrix.Data.dll". 应该是一个bug,估计 ...

  6. Unable to find remote helper for 'https'解决办法

    Unable to find remote helper for 'https'解决办法: 产生这个报错的原因一般是普通用户没权限调用git-remote-https所致 # ln -s /usr/l ...

  7. Git credential helper 让你的 https不再需要输入用户名密码

    前言 在使用Git进行开发的时候,我们可以使用ssh url或者http url来进行源码的clone/push/pull,二者的区别是,使用ssh url需要在本地配置ssh key,这也就意味着你 ...

  8. (转)[翻译] ASP.NET MVC Tip #1 - 使用扩展方法创建新的HTML Helper

    原文地址:http://weblogs.asp.net/stephenwalther/archive/2008/06/13/asp-net-mvc-tip-1-creating-new-html-he ...

  9. C# random helper class

    项目中经常需要模拟些假数据,来做测试.这个随机生成数据的helper类就应用而生: using System; using System.Text; using System.Windows.Medi ...

  10. .NET中的加密算法总结(自定义加密Helper类续)

    1.1.1 摘要 相信许多人都使用过.NET提供的加密算法,而且在使用的过程我们必须了解每种加密算法的特点(对称或非对称,密钥长度和初始化向量等等).我也看到过很多人写过.NET中加密算法总结,但我发 ...

最新文章

  1. python字符串删除,列表删除以及字典删除的总结
  2. php查询每个小时的数据,php – MySQL显示表中每小时的条目数
  3. GMIS 2017大会杨强演讲:迁移学习的挑战和六大突破点
  4. [WPF]WPF中材质制作——图片和矢量图之争
  5. How is Attachment property retrieved
  6. 对象引用 String引用 基本类型引用 差别
  7. 计算机主机温度,计算机的理想工作温度和湿度分别是多少
  8. php 抽象 接口类 区别,PHP 抽象類和接口區別
  9. (standard input): No keywords in input file
  10. 最新版:移动设备管理与OMA DM协议 V6
  11. 手机上的环境光传感器
  12. 解决minicom串口被锁Device /dev/ttyS? is locked
  13. 关于sqlserver身份登录失败的解决方法
  14. 2023山西大学计算机考研信息汇总
  15. Linux编译器-gcc/g++的使用
  16. 磁盘分区管理工具(DiskGenius Pro 5.3)pjb 附安装教程
  17. easyexcel的动态表头和自定义转换器
  18. 给出语言无符号整数的文法
  19. 解决vue双向绑定带来的问题
  20. 易源数据_易源数据-POI检索【最新版】_商业智能_数据API_金融-云市场-阿里云

热门文章

  1. wdtree简介、使用
  2. Lisp 的单行注释和多行注释
  3. decimal在存储过程和C#中的应用
  4. 跟我一起写 Makefile(一)【转】
  5. 基于koa2开发的用户中心
  6. Firefox 4网页演示:宣布Web O’Wonder的奇迹
  7. 自由自在意式手工冰淇淋式的生活方式
  8. 【备忘录】Product cost collectors – 成本收集器
  9. 【转载】IT新曙光——“遇事不决,量子力学” 的问与答
  10. 【MM模块】Reservation 预留