php 绘图技术

对于图像库中的函数 熟悉了一把。。做了个验证码的php脚本,另外看了 jpgraph 库里的一些函数。
对jpgraph的总结 ,他是php制作报表的一个库,自己下载配置。根据他给的例子改,不能再输出报表函数中输出其他的 东西。引用时用<img src="xx.php"></img>
比如说 我写了个输出报表的php文件 voteshow.php, 引用时用用<img src="voteshow.php" onlick="this.src='voteshow.php?aa='+Math.random()">,后面的onlick
是为了每次点击链接不一样,不让浏览器读取缓存,+是字符串相加,Math.random() 是因为调用random()方法需要在Math类下访问,下面是验证码的代码
<?php

    $str="";

    for($i=0;$i<4;$i++)
    {
        $str.=dechex (rand(0,15));// 随记一个1-15数字,然后将十进制转化成16进制,
    }
    
    $image= imagecreatetruecolor(110,30);
    $white= imagecolorallocate($image,144,144,144);
    imagefill($image,0,0,$white);// 填充画布的背景色

    $lineColor= imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255));
    session_start;
    $_SESSION['captcha']=$str;
    
    //画干扰线
    for($i=0;$i<=10;$i++){
    imageline($image,rand(0,110),rand(0,30),rand(55,110),rand(14,30),imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255)));
    }

    //输入字符到验证图片;
    imagestring($image,5,rand(0,40),rand(0,15),$str,$lineColor);
    

    header('content-type: image/png');
    imagepng($image);

    imagedestroy($image);
?>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章