zoukankan      html  css  js  c++  java
  • 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 $图片宽度,可选参数,默认为100  
    int $height:图片高度,可选参数,默认为100  
    int $autocut:是否自动裁切,可选参数,默认为1,为0时,将只等比压缩,可能出现图片变形  
    string $smallpic:无图片时显示的小图片地址,可选参数,默认为 images/nopic_small.gif  
    示例:
    {thumb($r[thumb], 160, 100,0)}
    解析:
    调用缩略图:{thumb(图片路径,宽为160,高为100,0为等比压缩)}

    ************************************************** *********************** ***************** 每个文章内容都是测试有效的
  • 相关阅读:
    win32
    win32
    win32
    win32
    C++ 指针的错误释放
    交换两个数不引入第三个变量
    交换两个数不引入第三个变量
    hdu3986 spfa + 枚举最短路上的边
    hdu3986 spfa + 枚举最短路上的边
    hdu2433 spfa+mark[x][u][v]优化
  • 原文地址:https://www.cnblogs.com/beijinglaolei/p/8184545.html
Copyright © 2011-2022 走看看