标签:blog class com code img http div java string javascript style
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 ?>
标签:blog class com code img http div java string javascript style
原文地址:http://www.cnblogs.com/ligangming/p/3694733.html