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

首頁 > 網站 > 建站經驗 > 正文

thumb函數生成等比縮略圖時變形的解決方法

2024-04-25 20:35:00
字體:
來源:轉載
供稿:網友

phpcms thumb函數生成縮略圖時,如果生成的比例一樣如1000*500的圖生成100*50的圖時會變形的解決方案:

如模板代碼為:

<img src="{thumb($r[url],150,120,0)}" alt="{$r[alt]}" title="{$r[alt]}"/>

圖片為960*768時,生成150*120時就會變形(這是我實際開發過程中用到的代碼)

找到phpcms/libs/images.class.php中找到getpercent函數(大數在49行),把此函數中的

$h = $dstw;

$w = $dsth;

改為

$h = $dsth;

$w = $dstw;

下面是改過后的整個函數,看代碼注釋

function getpercent($srcwidth,$srcheight,$dstw,$dsth) {

if (empty($srcwidth) || empty($srcheight) || ($srcwidth <= $dstW && $srcheight <= $dstH)) $w = $srcwidth ;$h = $srcheight;

if ((empty($dstw) || $dstw == 0) && $dsth > 0 && $srcheight > $dsth) {

$h = $dsth;

$w = round($dsth / $srcheight * $srcwidth);

} elseif ((empty($dsth) || $dsth == 0) && $dstw > 0 && $srcwidth > $dstw) {

$w = $dstw;

$h = round($dstw / $srcwidth * $srcheight);
} elseif ($dstw > 0 && $dsth > 0) {

if (($srcwidth / $dstw) < ($srcheight / $dsth)) {

$w = round($dsth / $srcheight * $srcwidth);

$h = $dsth;

}

elseif (($srcwidth / $dstw) > ($srcheight / $dsth)) {

$w = $dstw;

$h = round($dstw / $srcwidth *
$srcheight );

} else

//第一步:把以下兩行代碼注釋掉

//$h = $dstw;

//$w = $dsth;

//第二步:改為以下兩行代碼

$h = $dsth;

$w = $dstw;

}

}

$array['w'] = $w;

$array['h'] = $h;

return $array;

}

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江永县| 会宁县| 长顺县| 乡宁县| 河间市| 山西省| 灵丘县| 凤台县| 西藏| 丽江市| 芜湖县| 崇文区| 馆陶县| 舒兰市| 那曲县| 安徽省| 漯河市| 秦安县| 北宁市| 贵州省| 石林| 安平县| 宝清县| 始兴县| 尉氏县| 斗六市| 安乡县| 无为县| 兴化市| 调兵山市| 靖远县| 秦皇岛市| 错那县| 永昌县| 巴林左旗| 梁河县| 当阳市| 大邑县| 东乌珠穆沁旗| 论坛| 文成县|