![php 扭曲验证码,第1张 php 扭曲验证码,第1张](/aiimages/php+%E6%89%AD%E6%9B%B2%E9%AA%8C%E8%AF%81%E7%A0%81.png)
1 <?php
2
3 class image{
4 public static function code(){
5
6 $str=‘abcdefghijklmnopqrstuvwxyz0123456789‘;
7 $code = substr(str_shuffle($str),0,5);
8
9 // 2块
画布
10 $src = imagecreatetruecolor(60, 25);
11 $dst = imagecreatetruecolor(60, 25);
12
13 // 灰色背景
14 $sgray=imagecolorallocate($src, 200, 200, 200);
15 $dgray=imagecolorallocate($dst, 200, 200, 200);
16
17 //蓝色
18 $sblue=imagecolorallocate($src, 0, 0, 255);
19
20 imagefill($src, 0, 0, $sgray);
21 imagefill($dst, 0, 0, $dgray);
22
23 //写字
24 imagestring($src,5,0,0,$code,$sblue);
25
26 for($i=0;$i<60;$i++){
27
28 //根据
正弦曲线计算上下波动
29
30 for($i=0;$i<60;$i++){
31 $offset = 3;//最大波动几像素
32 $round = 2;//
扭动2个周期,2pie
33 $posY = round(sin($i *$round*2*M_PI/60)*$offset); //更具正弦曲线就算偏移量
34
35 imagecopy($dst, $src, $i, $posY, $i, 0, 1, 25);
36 }
37
38
39 }
40
41
42
43 header(‘Content-type: image/jpeg‘);
44 imagejpeg($dst);
45
46
47 }
48 }
49
50
51
52 //调用
53
54 image::code();
55
56 ?>
php 扭曲验证码,码迷,mamicode.com
php 扭曲验证码
评论列表(0条)