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);
?>


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