phpcms v9教程:thumb(縮略圖) 函數說明


打開phcmsc/libs/functions/global.func.php文件,找到如下代碼:
/**
 * 生成縮略圖函數
 * @param  $imgurl 圖片路徑
 * @param  $width  縮略圖寬度
 * @param  $height 縮略圖高度
 * @param  $autocut 是否自動裁剪 默認裁剪,當高度或寬度有一個數值為0是,自動關閉
 * @param  $smallpic 無圖片是默認圖片路徑
 */
function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1, $smallpic = 'nopic.gif') {
    global $image;
    $upload_url = pc_base::load_config('system','upload_url');
    $upload_path = pc_base::load_config('system','upload_path');
    if(empty($imgurl)) return IMG_PATH.$smallpic;
    $imgurl_replace= str_replace($upload_url, '', $imgurl);
    if(!extension_loaded('gd') || strpos($imgurl_replace, '://')) return $imgurl;
    if(!file_exists($upload_path.$imgurl_replace)) return IMG_PATH.$smallpic;

    list($width_t, $height_t, $type, $attr) = getimagesize($upload_path.$imgurl_replace);
    if($width>=$width_t || $height>=$height_t) return $imgurl;

    $newimgurl = dirname($imgurl_replace).'/thumb_'.$width.'_'.$height.'_'.basename($imgurl_replace);

    if(file_exists($upload_path.$newimgurl)) return $upload_url.$newimgurl;

    if(!is_object($image)) {
        pc_base::load_sys_class('image','','0');
        $image = new image(1,0);
    }
    return $image->thumb($upload_path.$imgurl_replace, $upload_path.$newimgurl, $width, $height, '', $autocut) ? $upload_url.$newimgurl : $imgurl;
}

此函數類似php手冊的表現形式為:
string thumb( string $imgurl, [int $width = 100], [int $height = 100], [int $autocut = 1], [string $smallpic = 'images/nopic_small.gif']  )
功能:
調用縮略圖
參數:
string $imgurl:圖片地址  
int $width:圖片寬度,可選參數,默認為100  
int $height:圖片高度,可選參數,默認為100  
int $autocut:是否自動裁切,可選參數,默認為1,為0時,將只等比壓縮,可能出現圖片變形  
string $smallpic:無圖片時顯示的小圖片地址,可選參數,默認為 images/nopic_small.gif  
示例:
{thumb($r[thumb], 160, 100,0)}
解析:
調用縮略圖:{thumb(圖片路徑,寬為160,高為100,0為等比壓縮)}
---------------------
作者:buzhang1314
來源:CSDN
原文:https://blog.csdn.net/buzhang1314/article/details/50675119
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM