当前位置:首页> PHP教程> php进阶
关键字
文章内容
图形随机码的生成。。
 
 
修改时间:[2011/04/29 16:20]    阅读次数:[1459]    发表者:[起缘]
 
效果:


<?php

$im 
imagecreate(4825);
    
    
$backgroundcolor imagecolorallocate ($im255255255);
    
$black imagecolorallocate($im,100,100,100);
    
$bordercolor imagecolorallocate($im 150150150);
    
    
//debug 增加图片的掺杂特性
    
$linenums mt_rand(1032);
    for(
$i=0$i <= $linenums$i++) {
        
$linecolor imagecolorallocate($immt_rand(0255), mt_rand(0255), mt_rand(0255));
        
$linex mt_rand(048);
        
$liney mt_rand(025);
        
imageline($im$linex$liney$linex mt_rand(04) - 2$liney mt_rand(04) - 2$linecolor);
    }    
    
    for(
$i=0$i <= 64$i++) {
        
$pointcolor imagecolorallocate($immt_rand(50255), mt_rand(50255), mt_rand(50255));
        
imagesetpixel($immt_rand(048), mt_rand(025), $pointcolor);
    }
    
    
$string "";
      
$arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','a','b');//把想要码的填进来
      
srand((double) microtime()*10000000);
      
$randcode array_rand($arr,4);
      for(
$i=0;$i<4;$i++){//生成4位随机数
      
$string .= $arr[$randcode[$i]];
      }

    
    
imagerectangle($im004724$bordercolor);
    
imagestring($im,7,4,4,$string,$black);    
    
//debug 合成图片
    
header('Content-type: image/png');
    
imagepng($im);
    
imagedestroy($im);

?> 


(非常全面的一个php技术网站, 有相当丰富的文章和源代码.)