1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| function ImageCode( $string='', $frames = 60, $time = 1,$width=75, $height=25, $font = 6, $loops = 0 ) { $authstr = $string?:((time()%2==0)?mt_rand(1000,9999):mt_rand(10000,99999)); $authlen = strlen($authstr); $board_width=$width; $board_height=$height; $delay = $time*100/$frames;
for($i=0;$i<$frames;$i++){ ob_start(); $image=imagecreate($board_width,$board_height); imagecolorallocate($image,0,0,0);
$colorList[]=imagecolorallocate($image,15,73,210); $colorList[]=imagecolorallocate($image,0,64,0); $colorList[]=imagecolorallocate($image,0,0,64); $colorList[]=imagecolorallocate($image,0,128,128); $colorList[]=imagecolorallocate($image,27,52,47); $colorList[]=imagecolorallocate($image,51,0,102); $colorList[]=imagecolorallocate($image,0,0,145); $colorList[]=imagecolorallocate($image,0,0,113); $colorList[]=imagecolorallocate($image,0,51,51); $colorList[]=imagecolorallocate($image,158,180,35); $colorList[]=imagecolorallocate($image,59,59,59); $colorList[]=imagecolorallocate($image,0,0,0); $colorList[]=imagecolorallocate($image,1,128,180); $colorList[]=imagecolorallocate($image,0,153,51); $colorList[]=imagecolorallocate($image,60,131,1); $colorList[]=imagecolorallocate($image,0,0,0); $gray=imagecolorallocate($image,245,245,245); imagefill($image,0,0,$gray); $space=$font*0.65;
for($k=0;$k<$authlen;$k++){ $colorRandom=mt_rand(0,sizeof($colorList)-1); $float_top=rand(0,4); $float_left=rand(1,4); imagettftext( $image, $font, 0, $space*$k+$float_left, $font+$float_top, $colorList[$colorRandom], './fonts/comic.ttf', substr($authstr,$k,1) ); } for($k=0;$k<20;$k++){ $colorRandom=mt_rand(0,sizeof($colorList)-1); imagesetpixel($image,rand()%70,rand()%15,$colorList[$colorRandom]);
} for($k=0;$k<3;$k++){ $colorRandom=mt_rand(0,sizeof($colorList)-1); $toDrawLine=1; if($toDrawLine){ imageline($image,mt_rand(0,$board_width),mt_rand(0,$board_height),mt_rand(0,$board_width),mt_rand(0,$board_height),$colorList[$colorRandom]); }else{ $w=mt_rand(0,$board_width); $h=mt_rand(0,$board_width); imagearc($image,$board_width-floor($w / 2),floor($h / 2),$w,$h, rand(90,180),rand(180,270),$colorList[$colorRandom]); } } imagegif($image); imagedestroy($image); $imagedata[]=ob_get_contents(); $delays[] = $delay; ob_clean(); } return new AnimatedGif($imagedata, $delays, $loops); }
|