教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP手机号码生成图片实例程序

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

发布时间:2016-10-26   编辑:jiaochengji.com
教程集为您提供PHP手机号码生成图片实例程序等资源,欢迎您收藏本站,我们将为您提供最新的PHP手机号码生成图片实例程序资源
以前做过一个招聘网站这样我们需要让别有采集不到我们客户的手机号码与邮箱地址了,所以我们会利用php实现从数据库读出来的手机号码与邮箱地址直接生成一张图片了,这样采集过去只能是图片并且无法识别了,下面我来给大家介绍两个实例。


PHP字符串处理-将手机号码生存图片

 

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7510')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7510>

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

    $str =  '13087263453';
    echo str_to_image($str,$w=130,$h=25,$rand=true)

例2

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8223')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8223>


<?php //前面不要有空行
$id=$_GET[id];
include("admin/config.php");
$sql="select * from user where id=$id";
$data=mysql_fetch_array(mysql_query($sql));
$p=SBC_DBC($data[Phone],1);
function get_str($str,$strlen=16) {
$str=stripslashes($str);
for($i=0;$i<$strlen;$i )
if(ord(substr($str,$i,1))>0xa0) $j ;
if($j%2!=0) $strlen ;
$tmp_str=substr($str,0,$strlen);
return $tmp_str;
}
if($p<>''){
//生成5位的数字图片
Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示

//定义图片宽高
$nwidth=120;
$nheight=25;
$im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); //建立图象

//图片色彩设置
$background_color=imagecolorallocate($im,255,255,255); //匹配颜色
$text_color=imagecolorallocate($im,23,14,91);

//绘制图片边框
imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色
imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形

//srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
//$randval=rand();
$randval=$p; //5位数
imagestring($im,8,10,2,$randval,$text_color); //绘制横式字串


//加入干扰因素
//for($i=0;$i<478;$i )
//{
//$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
//imagesetpixel($im,rand()0,rand()0,$randcolor); //点
//}
//imagestring($im,3,5,5,"A Simple Text String",$text_color);
//imageinterlace($im,1);
imagepng($im); //建立png图型
imagedestroy($im); //结束图型

}else{
echo "<font size=2>商家未输入电话号码</font>";
}

?>

您可能感兴趣的文章:
php随机生成4位数字验证码
php生成随机产生六位数密码的代码
php生成N个不重复的随机数
PHP手机号码生成图片实例程序
php生成随机数的例子
Python如何生成随机图形验证码
php生成随机数字和字母的实例代码
用php生成带有雪花背景的验证码
PHP随机显示指定文本(if elseif的用法)
php动态二维码如何生成

[关闭]
~ ~