如何后期自定义生成缩略图

浏览:470 发布日期:2015/08/18 分类:技术分享
首先要标签上支持
[list:indexpic $width=100 $height=100] 我是这样设定的

然后功能文件如下        if(!empty($width) or !empty($height)){
            if(empty($width) ){$width==0;}
            if(empty($height)){$height==0;} 
            $filemininame = str_ireplace('./','',$namevalue); //./uploadfile/201508/18/1439863987.jpg 变  uploadfile/201508/18/1439863987.jpg
            $filemininame = str_ireplace('/','',$filemininame); // uploadfile/201508/18/1439863987.jpg 变 uploadfile201508181439863987.jpg
            $filemininame = str_ireplace('uploadfile','',$filemininame); //uploadfile201508181439863987.jpg 变 201508181439863987.jpg
            $filemininame = str_ireplace('.','/'.$width.'x'.$height.'.',$filemininame); //生成所略图子路径 201508181439863987.jpg变201010291312299925/80x76.jpg 
            $smalldir = explode("/",$filemininame);
            $smalldir = "./uploadfile/small/".$smalldir[0];
            if (!file_exists($smalldir)){mkdir($smalldir);}//缩略图所需文件夹不存在就生成下 
            $file_mini='./uploadfile/small/'.$filemininame;
            if(!file_exists($file_mini)){ //不存在则生成 存在则跳过
                $image = new \Think\Image(); //初始化图片功能
                $image->open('.'.$namevalue); //打开原图
                $image->thumb($width,$height)->save($file_mini); 
            }
            $r = $file_mini;
        }     
最佳答案
评论( 相关
后面还有条评论,点击查看>>