中药方大全小图标
您当前的位置:首页 > 其他 > 网站日记

帝国cms之缩略图函数的修改-更好的支持瀑布流

提示: 阅读权限:公开  来源:jiuhecai  作者:jiuhecai

这里修改帝国的缩略图生成函数,使得能更好的适应瀑布流对缩率图的需求。该函数位于e/class/gd.php中。

当高度参数为10000的时候,以宽度为基准等比例缩放,高度不限。

当高度参数大于1万的时候,比如为10400,其含义为:以宽度为基准等比例缩放,高度限制为400像素,超过部分底部截取(保留上部)。

函数修改后如下:

 

//原文件,新文件,宽度,高度,维持比例

function ResizeImage($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1){
 if($max_height>10000){$max_height=$max_height-10000; $resize = 2;}

 $returnr['file']='';

 $returnr['filetype']='';

    if($temp_img_type = @getimagesize($big_image_name)) {preg_match('//([a-z]+)$/i', $temp_img_type[mime], $tpn); $img_type = $tpn[1];}

    else {preg_match('/.([a-z]+)$/i', $big_image_name, $tpn); $img_type = $tpn[1];}

    $all_type = array(

        "jpg"   => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),

        "gif"   => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif"   , "exn"=>".gif"),

        "jpeg"  => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),

        "png"   => array("create"=>"imagecreatefrompng" , "output"=>"imagepng"   , "exn"=>".png"),

        "wbmp"  => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")

    );

 

    $func_create = $all_type[$img_type]['create'];

    if(empty($func_create) or !function_exists($func_create))

 {

  return $returnr;

 }

 //输出

    $func_output = $all_type[$img_type]['output'];

    $func_exname = $all_type[$img_type]['exn'];

 if(($func_exname=='.gif'||$func_exname=='.png'||$func_exname=='.wbmp')&&!function_exists($func_output))

 {

  $func_output='imagejpeg';

  $func_exname='.jpg';

 }

    $big_image   = $func_create($big_image_name);

    $big_width   = imagesx($big_image);

    $big_height  = imagesy($big_image);

    if($big_width <= $max_width and $big_height <= $max_height)

 {

  $func_output($big_image, $new_name.$func_exname);

  $returnr['file']=$new_name.$func_exname;

  $returnr['filetype']=$func_exname;

  return $returnr;

 }

    $ratiow      = $max_width  / $big_width;

    $ratioh      = $max_height / $big_height;
 // jiuhcecai add
 if($max_height == 10000){
  $ratioh=$ratiow;
     $max_height=$ratioh* $big_height;

 }
    if($resize == 1) {

        if($big_width >= $max_width and $big_height >= $max_height)

        {

            if($big_width > $big_height)

            {

            $tempx  = $max_width / $ratioh;

            $tempy  = $big_height;

            $srcX   = ($big_width - $tempx) / 2;

            $srcY   = 0;

            } else {

            $tempy  = $max_height / $ratiow;

            $tempx  = $big_width;

            $srcY   = ($big_height - $tempy) / 2;

            $srcX   = 0;

            }

        } else {

            if($big_width > $big_height)

            {

            $tempx  = $max_width;

            $tempy  = $big_height;

            $srcX   = ($big_width - $tempx) / 2;

            $srcY   = 0;

            } else {

            $tempy  = $max_height;

            $tempx  = $big_width;

            $srcY   = ($big_height - $tempy) / 2;

            $srcX   = 0;

            }

        }

    }elseif($resize == 2) // 以宽为准,适合瀑布流
 {
  $ratioh=$ratiow;
  $tempHeight=$ratiow*$big_height;
  $srcX      = 0;
        $srcY      = 0;
        $tempx     = $big_width;
        $tempy     = $big_height;
  if($tempHeight>$max_height)$tempy =$max_height/$ratiow;
        $max_height=$ratiow*$tempy;
 }else
 {
  
   

        $srcX      = 0;

        $srcY      = 0;

        $tempx     = $big_width;

        $tempy     = $big_height;

    }

 

    $new_width  = ($ratiow  > 1) ? $big_width  : $max_width;

    $new_height = ($ratioh  > 1) ? $big_height : $max_height;

    if(function_exists("imagecopyresampled"))

    {

        $temp_image = imagecreatetruecolor($new_width, $new_height);

        imagecopyresampled($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);

    } else {

        $temp_image = imagecreate($new_width, $new_height);

        imagecopyresized($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);

    }

        $func_output($temp_image, $new_name.$func_exname);

        ImageDestroy($big_image);

        ImageDestroy($temp_image);

  $returnr['file']=$new_name.$func_exname;

  $returnr['filetype']=$func_exname;

    return $returnr;

}

 

 

tags: 帝国cms 帝国 缩略图 瀑布流 瀑布
返回顶部
推荐资讯
视频:田纪钧讲关节不痛的秘密、膝关节拉筋法
视频:田纪钧讲关节不
白露到了,你还好吗?
白露到了,你还好吗?
尿疗与断食
尿疗与断食
给风疹反复发作女孩的药方(组图)
给风疹反复发作女孩的
相关文章
栏目更新
栏目热门
  1. 帝国cms全站搜索的分页格式如何修改-流程
  2. libreoffice7的命令大全
  3. 帝国cms插件之标题生成标题图片
  4. 帝国cms插件安装模板
  5. useragent两千条,爬虫专用
  6. 帝国cms插件之迅搜
  7. 帝国cms插件如何兼容gbk和utf8
  8. 帝国cms用户上传文件名的命名规则及修改方
  9. 帝国cms代码片段备忘录
  10. 帝国cms7.2函数大全