分类分类
更新时间:2026-02-18 19:50:15作者:sa
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;
}
相关
归墟战纪策略游戏262.92 MBv3.95802026-02-14
下载爆裂老奶策略游戏209.43 MBv1.0.112026-02-14
下载超能下蛋鸭策略游戏395.4 MBv1.2.82026-02-14
下载你好盒子实用工具12.1 MBv2.2.852026-02-14
下载我在峡谷当牛马休闲益智87.95 MBv0.7.12026-02-14
下载抽卡监狱2策略游戏190.75 MBv1.4.92026-02-14
下载Campus社交通讯94.36 MBv1.19.02026-02-14
下载冒险传奇角色扮演141.73 Mv9991.12026-02-14
下载心动次元app社交通讯43.96 Mv1.0.1.32026-02-14
下载致亲爱的我角色扮演1.63Gv1.02026-02-14
下载狼伴侣游戏手机版冒险游戏155.6 Mv1.02026-02-14
下载Loclike社交通讯169.08 Mv2.2.112026-02-14
下载










