茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    php生成驗證碼,縮略圖及水印圖的類分享
    來源:易賢網(wǎng) 閱讀:1045 次 日期:2016-08-27 13:12:07
    溫馨提示:易賢網(wǎng)小編為您整理了“php生成驗證碼,縮略圖及水印圖的類分享”,方便廣大網(wǎng)友查閱!

    封裝了一個類,可生成驗證碼,縮略圖,及水印圖,分享給大家

    <?php

    class image{

      session_start();

      //驗證碼類

      static public function verify($code,$width=75,$height=25,$n=4){

        header("content-type:image/png");

        // 創(chuàng)建畫布

        $img=imagecreatetruecolor($width,$height);

        // 設置背景色

        $bgcolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));

        // 將背景色填充

        imagefill($img,0,0,$bgcolor);

        // 繪制五條弧線

        for($i=0;$i<5;$i++){

          $arccolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));

          imagearc($img,mt_rand(5,($width-5)),mt_rand(5,($height-5)),mt_rand(5,($width-5)),mt_rand(5,($height-5)),mt_rand(0,360),mt_rand(0,360),$arccolor);

        }

        // 繪制一百個點

        for($i=0;$i<100;$i++){

          $pixelcolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));

          imagesetpixel($img,mt_rand(1,($width-1)),mt_rand(1,($height-1)),$pixelcolor);

        }

        // 繪制五條線段

        for($i=0;$i<5;$i++){

          $linecolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));

          imageline($img,mt_rand(1,($width-1)),mt_rand(1,($height-1)),mt_rand(1,($width-1)),mt_rand(1,($height-1)),$linecolor);

        }

        // 設置邊框顏色

        $bdcolor=imagecolorallocate($img,mt_rand(150,200),mt_rand(150,200),rand(150,200));

        // 繪制一個矩形無填充邊框

        imagerectangle($img,0,0,($width-1),($height-1),$bdcolor);

        // 設置驗證碼字符串

        $str='';

        for($i=1;$i<=$n;$i++){

          $str.=substr(str_shuffle($code),0,1);

        }

        $_SESSION['a']=$str;

        //

        for($i=0;$i<$n;$i++){

          $textcolor=imagecolorallocate($img,mt_rand(100,150),mt_rand(100,150),mt_rand(100,150));

          imagettftext($img,1/($n+1)*$width,mt_rand(-20,20),((1-$n/(5+$n))*$width/($n-1)+$i*1/($n+1)*$width),1/2*($height+3/5*$height),$textcolor,'1.ttf',substr($str,$i,1));

        }

        // 打印圖像

        imagepng($img);

        // 釋放資源

        imagedestroy($img);

        return $str;

      }

      //縮略圖類

      /*

      *$source需要縮略的圖片

      */

      static public function thumbnail($source,$deletesource=false,$width=180){

        $info=getimagesize($source);

        //getimagesize方法獲得圖像的詳細信息

        $createFun=str_replace('/','createfrom',$info['mime']);

        //將getimagesize中的['mime']中的/替換,變?yōu)閕magecreatefromjpeg方法

        $src=$createFun($source);

        //創(chuàng)建圖像

        $dst_w=$width;

        //縮略圖的寬

        $dst_h=$width/$info[0]*$info[1];

        //計算縮略圖的高

        $dst=imagecreatetruecolor($dst_w,$dst_h);

        //新建一個真彩色圖像

        imagecopyresampled($dst,$src,0,0,0,0,$dst_w,$dst_h,$info['0'],$info['1']);

        //重采樣拷貝部分圖像并調(diào)整大小

        $saveFun=str_replace('/','',$info['mime']);

        //設置保存函數(shù)

        $ext=strrchr($source,'.');

        //strrchr查找指定字符在字符串中的最后一次出現(xiàn),返回包括其自身在內(nèi)的剩余的字符串

        $thumbnailName=str_replace($ext,'',$source).'_thumbnail'.$ext;

        //設置保存路徑

        if(!$deletesource){

          $saveFun($dst,$thumbnailName);

          //保存圖像

        }else{

          $saveFun($dst,$thumbnailName);

          unlink($source);

          //刪除原圖

        }

        imagedestroy($src);

        //銷毀資源

        imagedestroy($dst);

        //銷毀資源

        return $thumbnailName;

      }

      //水印圖類

      /*

      *$srcing水印圖

      *$dsting原圖

      */

      static public function watermark($dstimg,$srcimg){

        $dstinfo=getimagesize($dstimg);

        //getimagesize方法獲取該圖片的詳細信息(該方法返回的是一個詳細的數(shù)組)

        $srcinfo=getimagesize($srcimg);

        $createdst=str_replace('/','createfrom',$dstinfo['mime']);

        //將getimagesize方法返回的數(shù)組中的mime值中的/替換,結果為imagecreatefromjpeg

        $createsrc=str_replace('/','createfrom',$srcinfo['mime']);

        $dst=$createdst($dstimg);

        //替換后為imagecreatefromjpeg函數(shù),創(chuàng)建一個圖像

        $dst_w=imagesx($dst);

        //獲取大圖的寬

        $dst_h=imagesy($dst);

        //獲取大圖的高

        $src=$createsrc($srcimg);

        //替換后為imagecreatefromjpeg函數(shù),創(chuàng)建一個圖像

        $src_w=imagesx($src);

        //獲取水印圖的寬

        $src_h=imagesy($src);

        //獲取水印圖的高

        $watermaker=imagecopy($dst,$src,($dst_w-$src_w),($dst_h-$src_h),0,0,$src_w,$src_h);

        //將水印圖復制在大圖上

        $saveFun=str_replace('/','',$dstinfo['mime']);

        //將getimagesize返回數(shù)組中的['mime']中的斜杠替換為空,替換后的值為imagejpeg,即為保存函數(shù)

        $ext=strrchr($dstimg,'.');

        //strrchr查找指定字符在字符串中的最后一次出現(xiàn),返回包括其自身在內(nèi)的剩余的字符串

        $watermaker=str_replace($ext,'',$dstimg).'_water'.time().$ext;

        //保存名

        $saveFun($dst,$watermaker);

        //保存圖片,第一個參數(shù)為要保存的圖片,第二個參數(shù)為保存路徑或保存名

        imagedestroy($dst);

        //銷毀資源

        imagedestroy($src);

        //銷毀資源

        return $watermaker;

      }

    }

    ?>

    更多信息請查看網(wǎng)絡編程
    易賢網(wǎng)手機網(wǎng)站地址:php生成驗證碼,縮略圖及水印圖的類分享

    2026國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)