php中的thumb函数,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為等比壓縮)}
參考網站:
周口市工信局(phpcms制作)
中國健康網盟(dedecms/織夢制作)
聯系qq:3143542926(點擊進行咨詢)
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的php中的thumb函数,phpcms v9教程:thumb(缩略图) 函数说明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php读程序,PHP 读取大文件程序代码
- 下一篇: oracle中做数据字典,oracle中