中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

生成圖片縮略圖PHP函數(shù)

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
    <?php  
    /** 
     * 生成縮略圖函數(shù)(支持圖片格式:gif、jpeg、png和bmp) 
     * @author ruxing.li 
     * @param  string $src      源圖片路徑 
     * @param  int    $width    縮略圖寬度(只指定高度時進(jìn)行等比縮放) 
     * @param  int    $width    縮略圖高度(只指定寬度時進(jìn)行等比縮放) 
     * @param  string $filename 保存路徑(不指定時直接輸出到瀏覽器) 
     * @return bool 
     */  
    function mkThumbnail($src, $width = null, $height = null, $filename = null) {  
        if (!isset($width) && !isset($height))  
            return false;  
        if (isset($width) && $width <= 0)  
            return false;  
        if (isset($height) && $height <= 0)  
            return false;  
      
        $size = getimagesize($src);  
        if (!$size)  
            return false;  
      
        list($src_w, $src_h, $src_type) = $size;  
        $src_mime = $size['mime'];  
        switch($src_type) {  
            case 1 :  
                $img_type = 'gif';  
                break;  
            case 2 :  
                $img_type = 'jpeg';  
                break;  
            case 3 :  
                $img_type = 'png';  
                break;  
            case 15 :  
                $img_type = 'wbmp';  
                break;  
            default :  
                return false;  
        }  
      
        if (!isset($width))  
            $width = $src_w * ($height / $src_h);  
        if (!isset($height))  
            $height = $src_h * ($width / $src_w);  
      
        $imagecreatefunc = 'imagecreatefrom' . $img_type;  
        $src_img = $imagecreatefunc($src);  
        $dest_img = imagecreatetruecolor($width, $height);  
        imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $width, $height, $src_w, $src_h);  
      
        $imagefunc = 'image' . $img_type;  
        if ($filename) {  
            $imagefunc($dest_img, $filename);  
        } else {  
            header('Content-Type: ' . $src_mime);  
            $imagefunc($dest_img);  
        }  
        imagedestroy($src_img);  
        imagedestroy($dest_img);  
        return true;  
    }  
      
    $result = mkThumbnail('./IMG_3324.JPG', 147, 147);  

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:php來實(shí)現(xiàn)telnet的連接、傳遞命令、獲取返回值等功能

下一篇:Python數(shù)據(jù)庫連接池DBUtils.PooledDB