国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Discuz > 正文

discuz x3.2 提取帖子第一張圖片生成縮略圖代碼

2024-09-11 09:05:28
字體:
來源:轉載
供稿:網友
在已獲得帖子圖片附件aid的情況下可以直接使用
<!--{eval $imagelistkey = getforumimg($thecover[aid], 0, 225, 0); }-->
這個是生成到data/attachment目錄。

或者另一種,在只有帖子tid的情況下獲得帖子縮略圖,單獨創建aidpic.php文件放到根目錄,在使用時縮略圖地址為aidpic.php?aid=帖子tid&寬x高,如<img src="aidpic.php?aid=24575&size=150x100"/>
生成到自動創建data/aidpic。
<?phprequire_once './source/class/class_core.php';$discuz = & discuz_core::instance();$discuz->init();list($w,$h)=explode("x",$_G['gp_size']);$m=0;if($w==0&&$h==0){        $m=5;}elseif ($h==0){        $m=3;}elseif ($w==0){        $m=4;}/*$w=100;//寬度$h=75;//高度$m=0;//縮略圖模式        //mode=0為固定寬高,畫質裁切不變形        //mode=1為固定寬高,畫質會拉伸變形        //mode=2為可變寬高,寬高不超過指定大小        //mode=3為固定寬度,高度隨比例變化*/$nopic='./static/image/common/nophotosmall.gif';//缺省圖片$aid=intval($_G['gp_aid']);$dir="data/aidpic/";$subdir=$dir."/{$w}x{$h}x{$m}/";$thumbfile=$subdir."/".$aid.".jpg";if(file_exists($thumbfile)){        header("location:{$thumbfile}");        die();}$tableid=substr($aid,-1,1);$attach=DB::fetch_first("SELECT a.tid,a.attachment,a.remoteFROM ".DB::table("forum_attachment_{$tableid}")." aWHERE a.`tid` ='$aid'AND a.`isimage`<>0order by a.aid asclimit 0,1");if($attach){        $attachurl=$attach['remote']?$_G['setting']['ftp']['attachurl']:$_G['setting']['attachurl'];        $attachfile=$attachurl."/forum/".$attach['attachment'];        if(!is_dir($dir)) @mkdir($dir);        if(!is_dir($subdir)) @mkdir($subdir);        dzthumb($attachfile,$thumbfile,$w,$h,$m);        header("location:{$thumbfile}");        die();}else{        header("location:$nopic");        die();}function dzthumb($srcfile,$dstfile,$dstw,$dsth=0,$mode=0,$data=''){        $data=$data==''?@GetImageSize($srcfile):$data;        if(!$data) return false;        if($data[2]==2) $im=@ImageCreateFromJPEG($srcfile);        elseif ($data[2]==1) $im=@ImageCreateFromGIF($srcfile);        elseif($data[2]==3) $im=@ImageCreateFromPNG($srcfile);        list($img_w, $img_h) = $data;        if($dsth==0) $mode=3;        if($mode==0){                $imgratio = $img_w / $img_h;                $thumbratio = $dstw / $dsth;                if($imgratio >= 1 && $imgratio >= $thumbratio || $imgratio < 1 && $imgratio > $thumbratio) {                        $cuty = $img_h;                        $cutx = $cuty * $thumbratio;                } elseif($imgratio >= 1 && $imgratio <= $thumbratio || $imgratio < 1 && $imgratio < $thumbratio) {                        $cutx = $img_w;                        $cuty = $cutx / $thumbratio;                }                $cx = $cutx;                $cy = $cuty;        }elseif($mode==1){                $cx = $img_w;                $cy = $img_h;        }elseif ($mode==2){                $cx = $img_w;                $cy = $img_h;                $bit=$img_w/$img_h;                if($dstw/$dsth>$bit){                        $dstw=($img_w/$img_h)*$dsth;                }else{                        $dsth=($img_h/$img_w)*$dstw;                }        }        elseif($mode==3){                $cx = $img_w;                $cy = $img_h;                $dsth=$dstw * $img_h / $img_w;        }        elseif ($mode==4){                $cx = $img_w;                $cy = $img_h;                $dstw=$dsth * $img_w / $img_h;        }        $ni=imagecreatetruecolor($dstw,$dsth);        ImageCopyResampled($ni,$im,0,0,0,0,$dstw,$dsth, $cx, $cy);        clearstatcache();        if($data[2]==2) ImageJPEG($ni,$dstfile,100);        elseif($data[2]==1) ImageGif($ni,$dstfile);        elseif($data[2]==3) ImagePNG($ni,$dstfile);        return true;}?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昌江| 南溪县| 波密县| 陈巴尔虎旗| 达孜县| 泽普县| 九寨沟县| 邻水| 清镇市| 灵台县| 扬中市| 林芝县| 宜君县| 呼伦贝尔市| 浏阳市| 凤凰县| 汝阳县| 黄浦区| 那曲县| 新密市| 嘉鱼县| 江西省| 河曲县| 保山市| 武义县| 金平| 朝阳市| 浏阳市| 黔江区| 饶平县| 子长县| 山东| 板桥市| 理塘县| 福贡县| 张家港市| 阿鲁科尔沁旗| 手机| 巍山| 丹江口市| 屯昌县|