PHP--中文验证码

01.php
<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


/***
图片里写中文,并做中文验证码

array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

***/


// 创建画布
$im = imagecreatefromjpeg('./home.jpg');

// 创建颜料
$blue = imagecolorallocate($im,0,0,255);

// 写字
imagettftext($im,25,30,327,157,$blue,'./msyh.ttf','加州水郡');


// 输出或保存
header('content-type: image/jpeg');
imagejpeg($im);


// 销毁
imagedestroy($im);




02.php

<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


/***
====笔记部分====
中文验证码

如何产生随机的中文字符串?
中文按其unicode编码,是有规律的,
位于0x4E00-0x9FA0
我们可以在uncode范围内随机选取,

但是 请注意,对于用户来说,能否认得?
因为有大量生僻字.


所以在实际项目中,只是抽取几百或上千个常用汉字,放数组里,随机选取.
***/


$char = array('中','华','人','民','共','和','国');
shuffle($char);
$code = implode('',array_slice($char,0,4));


// 画布
$im = imagecreatetruecolor(65,25);

// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);


// 填充
imagefill($im,0,0,$gray);

// 写字
imagettftext($im,12,0,2,20,$blue,'./msyh.ttf',$code);


// 输出
header('content-type: image/jpeg;');
imagejpeg($im);

//销毁
imagedestroy($im);






03.php
<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


/***
====笔记部分====
画复杂图形,并填充

矩形
椭圆
圆弧(统计时的饼状图,要用到)
***/



// 画布
$im = imagecreatetruecolor(800,600);


// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);
$red = imagecolorallocate($im,255,0,0);

// 填充
imagefill($im,0,0,$gray);



// 画一个矩形
/*
bool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col )
参数: 画布资源, 左上角x坐标,左上y坐标,右下x坐标,右下y坐标,颜色
*/


imagerectangle($im,200,150,600,450,$blue);



// 画椭圆
/*
bool imageellipse ( resource $image , int $cx , int $cy , int $w , int $h , int $color )
参数:画布资源,圆心x坐标,圆心y坐标,宽,高,颜色
*/
imageellipse ( $im , 400 , 300 , 400 , 300 , $red );
imageellipse ( $im , 400 , 300 , 300 , 300 , $red );
imageellipse ( $im , 400 , 300 , 200 , 300 , $red );
imageellipse ( $im , 400 , 300 , 100 , 300 , $red );

// 输出
header('content-type: image/jpeg;');
imagejpeg($im);

//销毁
imagedestroy($im);



04.php

<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


/***
====笔记部分====
画复杂图形,并填充

矩形
椭圆
圆弧(统计时的饼状图,要用到)
***/



// 画布
$im = imagecreatetruecolor(800,600);


// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);
$red = imagecolorallocate($im,255,0,0);

// 填充
imagefill($im,0,0,$gray);



// 画一个矩形并填充
/*
bool imagefilrectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col )
参数: 画布资源, 左上角x坐标,左上y坐标,右下x坐标,右下y坐标,颜色
*/


imagefilledrectangle($im,200,150,600,450,$blue);



// 画椭圆并填充
/*
bool imagefilledellipse ( resource $image , int $cx , int $cy , int $w , int $h , int $color )
参数:画布资源,圆心x坐标,圆心y坐标,宽,高,颜色
*/
imagefilledellipse ( $im , 400 , 300 , 400 , 300 , $red );
imagefilledellipse ( $im , 400 , 300 , 300 , 300 , $blue );
imagefilledellipse ( $im , 400 , 300 , 200 , 300 , $red );
imagefilledellipse ( $im , 400 , 300 , 100 , 300 , $blue );

// 输出
header('content-type: image/jpeg;');
imagejpeg($im);

//销毁
imagedestroy($im);



05.php

<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


/***
====笔记部分====
画饼图
其实就是画圆弧
***/



// 画布
$im = imagecreatetruecolor(800,600);


// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);
$red = imagecolorallocate($im,255,0,0);

// 填充
imagefill($im,0,0,$gray);


/*
画一段圆弧
bool imagearc ( resource $image , int $cx , int $cy , int $w , int $h , int $s , int $e , int $color )
参数为: 画布,圆心x值,圆心y值,宽,高,起始角度,结果角度,颜色
*/
imagearc($im,400,300,300,300,270,0,$blue);
imagearc($im,400,300,310,310,-90,0,$red);
// 输出
header('content-type: image/jpeg;');
imagejpeg($im);

//销毁
imagedestroy($im);



06.php


<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


/***
====笔记部分====
画饼图
画圆弧并填充
***/



// 画布
$im = imagecreatetruecolor(800,600);


// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);
$red = imagecolorallocate($im,255,0,0);

// 填充
imagefill($im,0,0,$gray);


/*
画一段圆弧并填充
bool imagefilledarc ( resource $image , int $cx , int $cy , int $w , int $h , int $s , int $e , int $color , int $style )

参数为: 画布,圆心x值,圆心y值,宽,高,起始角度,结果角度,颜色,填充方式

1 IMG_ARC_CHORD 直线连圆弧2端
0 IMG_ARC_PIE   弧线连圆弧2端
4 IMG_ARC_EDGED 指明用直线将起始和结束点与中心点相连,
2 IMG_ARC_NOFILL 不填充轮廓(默认是填充的)

*/

imagefilledarc($im,400,300,300,300,270,0,$blue,1+2+4);


imagefilledarc($im,0,400,310,310,0,45,$blue,0+4);
imagefilledarc($im,0,400,300,300,0,45,$red,0+4);
// 输出
header('content-type: image/jpeg;');
imagejpeg($im);

//销毁
imagedestroy($im);




07.php

<?php
/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/


/*
imagefill的用法
*/


// 画布
$im = imagecreatetruecolor(800,600);


// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);
$red = imagecolorallocate($im,255,0,0);


// 填充
imagefill($im,200,200,$gray);

imageellipse($im,400,300,300,300,$blue);


// 再次填充
imagefill($im,400,300,$red);


// 输出
header('content-type: image/jpeg;');
imagejpeg($im);

//销毁
imagedestroy($im);








  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值