联系电话:0755-27515592
最新动态:

PHP教程

你的位置: 首页>>智慧亿恩>>PHP教程

PHP手机号码生成图片实例程序

点击数:19532015-07-31 10:36:48 来源: 外贸网站建设,深圳外贸网站建设,深圳网站建设,外贸商城网站制作-亿恩科技

新闻摘要:以前做过一个招聘网站这样我们需要让别有采集不到我们客户的手机号码与邮箱地址了,所以我们会利用php实现从数据库读出来的手机号码与邮箱地址直接生成一张图片了,这样采集过去

以前做过一个招聘网站这样我们需要让别有采集不到我们客户的手机号码与邮箱地址了,所以我们会利用php实现从数据库读出来的手机号码与邮箱地址直接生成一张图片了,这样采集过去只能是图片并且无法识别了,下面我来给大家介绍两个实例.

PHP字符串处理-将手机号码生存图片,代码如下:

  1. ////电话号码转变成图片 
  2.     //$str 要显示的字串,$rand是否启用扰码 
  3.     function str_to_image($str,$w=130,$h=25,$rand=true) 
  4.     { 
  5.        //生成11位的数字图片  
  6.        Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示  
  7.        //定义图片宽高  
  8.        $nwidth=$w
  9.        $nheight=$h
  10.        //srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子  
  11.        $randval=$str//11位数  
  12.        $im=@imagecreate($nwidth,$nheightor die("Can't initialize new GD image stream"); //建立图象  
  13.        //图片色彩设置  
  14.        $background_color=imagecolorallocate($im,255,255,255); //匹配颜色  
  15.        $text_color=imagecolorallocate($im,23,14,91); 
  16.        //绘制图片边框  
  17.        imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色  
  18.        imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形  
  19.        imagestring($im,8,10,4,$randval,$text_color); //绘制横式字串  
  20.        if($rand){ 
  21.            //加入干扰因素  
  22.            for($i=0;$i<260;$i++) 
  23.            { 
  24.                $randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); 
  25.                imagesetpixel($im,rand()%($nwidth-5),rand()%($nheight+5),$randcolor); //点  
  26.            } 
  27.        } 
  28.        //imagestring($im,3,5,5,"A Simple Text String",$text_color);  
  29.        //imageinterlace($im,1);  
  30.        imagepng($im); //建立png图型  
  31.        imagedestroy($im); //结束图型 
  32.     } 
  33.  
  34.     $str =  '13087263453'
  35.     echo str_to_image($str,$w=130,$h=25,$rand=true) 

例2,代码如下:

  1. <?php //前面不要有空行  
  2. $id=$_GET[id];  
  3. include("admin/config.php");  
  4. $sql="select * from user where id=$id";  
  5. $data=mysql_fetch_array(mysql_query($sql));  
  6. $p=SBC_DBC($data[Phone],1);  
  7. function get_str($str,$strlen=16) {  
  8. $str=stripslashes($str);  
  9. for($i=0;$i<$strlen;$i++)  
  10. if(ord(substr($str,$i,1))>0xa0) $j++;  
  11. if($j%2!=0) $strlen++;  
  12. $tmp_str=substr($str,0,$strlen);  
  13. return $tmp_str;  
  14. }  
  15. if($p<>''){  
  16. //生成5位的数字图片  
  17. Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示 
  18.  
  19. //定义图片宽高  
  20. $nwidth=120;  
  21. $nheight=25;  
  22. $im=@imagecreate($nwidth,$nheightor die("Can't initialize new GD image stream"); //建立图象 
  23.  
  24. //图片色彩设置  
  25. $background_color=imagecolorallocate($im,255,255,255); //匹配颜色  
  26. $text_color=imagecolorallocate($im,23,14,91); 
  27.  
  28. //绘制图片边框  
  29. imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色  
  30. imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形 
  31.  
  32. //srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子  
  33. //$randval=rand();  
  34. $randval=$p//5位数  
  35. imagestring($im,8,10,2,$randval,$text_color); //绘制横式字串 
  36.  
  37.  
  38. //加入干扰因素  
  39. //for($i=0;$i<478;$i++)  
  40. //{  
  41. //$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));  
  42. //imagesetpixel($im,rand()%100,rand()%30,$randcolor); //点  
  43. //}  
【责任编辑:(Top) 返回页面顶端
贴心
全国7×24小时客服热线
安全
病毒杀除率高于99%
稳定
网站可用性高于99.9%
实力
服务68家上市企业及集团公司
亿恩科技手机站
关注亿恩科技微信

亿恩科技—企业信息化一站式服务专家


Copyright © 2008- 深圳市亿恩科技有限公司版权所有 粤ICP备15056041号

联系我们 | 常见问题 | 在线留言 | 支付方式 | 软件开发 | 我的观点 | 资质荣誉 | 服务流程