首页 > Web开发 > 详细

phpcms v9教程:thumb(缩略图) 函数说明

时间:2019-06-02 14:01:16      阅读:141      评论:0      收藏:0      [点我收藏+]

打开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
版权声明:本文为博主原创文章,转载请附上博文链接!

phpcms v9教程:thumb(缩略图) 函数说明

原文:https://www.cnblogs.com/jxhgt/p/10962635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!