<?php
class image {
public static function code(){
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz023456789';
$code = substr(str_shuffle($str),0,4);
$src= imagecreatetruecolor(60,25);
$dst = imagecreatetruecolor(60,25);
$sgray = imagecolorallocate($src,128,128,128);
$dgray =imagecolorallocate($dst,128,128,128);
$sblue = imagecolorallocate($src,255,255,255);
imagefill($src,0,0,$sgray);
imagefill($dst,0,0,$dgray);
imagestring($src,5,5,4,$code,$sblue);
for($i=0;$i<60;$i++){
$offset = 3;//最大波动几个像素,纵向
$round = 2;//扭2个周期,横向
$posy = round(sin($i*$round*2*M_PI /60)*$offset);
//round函数,是四舍五入用的,sin函数返回的是小数型
imagecopy($dst,$src,$i,$posy,$i,0,1,25);
}
// 输出图像
header ( "content-type: image/jpeg" );
imagejpeg ( $dst);
}
}