分类分类
更新时间:2026-05-10 22:02:07作者: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;
}
相关
修真情缘角色扮演303.33 MBv1.0.02026-05-10
下载我的小独角兽女孩休闲益智380.89 MBv1.0.232026-05-10
下载超级种田男孩手机版经营养成1.31Gv1.0.92026-05-10
下载不必要的实验冒险游戏64.9 MBv1.1.592026-05-10
下载军师联盟策略游戏163.2 MBv0.0.12026-05-10
下载翻天喜地凑大钱手机版休闲益智138.72 MBv1.0.92026-05-10
下载东离剑游纪手游动作射击1.6Gv1.4.22026-05-10
下载天猫养车商家版App学习办公74.95 MBv0.6.12026-05-10
下载掌上命运方舟App手游辅助137.48 MBv1.9.12026-05-10
下载退役军人服务APP生活服务67.16 MBv1.2.52026-05-10
下载屯漫漫画APP资讯阅读23.06 MBv2.0.32026-05-10
下载蛋仔派对蛋壳App手游辅助185.73 MBv0.0.22026-05-10
下载









